No matching function for call to error

Here is my coding:


factory.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "factory.h"
#include <algorithm>
#include <iostream>

using namespace std;


Factory::Factory ()
  : numOrders(0), maxOrders(4)
{
  orders = new Order[maxOrders];
}


Factory::Factory (std::string nm)
  : numOrders(0), maxOrders(4), name(nm)
{
  orders = new Order[maxOrders];
}


// Clear all orders for this factory
void Factory::clearOrders()
{
  numOrders = 0;
}

// Place an order for some number of items.
// If a prior order has been placed for these, this additional
// order adds to that prior one. The Item is also updated to reflect
// the change in total number of that item ordered by all factories.
void Factory::orderItems (Item* itemToOrder, int numToOrder)
{
  int k = 0;
  while (k < numOrders && orders[k].item->name != itemToOrder->name) //while k is less then numOrders and the order item name is not the itemToOrder name// /Bacically, while the number of orders
    ++k;                                                             //add one to k                                                                        Hasnt been updated and while you arent on the
  if (k < numOrders && orders[k].item == itemToOrder)                //If k is less than the number of orders and the order item is the item to order      right item anyways
    {
      // This factory already has an order for some of these items
     // cerr<<"Orders Amount = "<<orders[k].amount;
      orders[k].amount += numToOrder;                                //then add the number of the order to the orders that have already been requested
    }
  else                                                               //or else
    {
      // A new item for this factory - add it
      if (numOrders >= maxOrders)                                    //if the numOrders is greater then or equal to the maxOrders
	{
	  Order* newOrders = new Order[2*maxOrders];                     //then create a new order
	  copy (orders, orders+numOrders, newOrders);                    ///and copy the old orders into a new order   CHECK THIS OUT   MAYBE OPERATOR OVERLOADING?
	  delete [] orders;                                              //delete the old orders
	  orders = newOrders;                                            //put the neworders into the orders array (using operator overloading)
	  maxOrders *= 2;                                                //maxOrders = maxOrders * 2
	}
      orders[numOrders] = Order(itemToOrder, numToOrder);             //
      int k = numOrders;                                              //k equals the number of orders
      while (k > 0 && orders[k].item->name < orders[k-1].item->name)  //while k is greater than zero and
	{
	  swap (orders[k], orders[k-1]);
	  --k;
	}
      ++numOrders;


    }

  // Update the total ordered of this item
  itemToOrder->amount += numToOrder ;
  //itemToOrder->amount;

}

// Access to Orders (in alphabetic order by item name)
Factory::OrderPosition Factory::begin() const
{
  return orders;
}

Factory::OrderPosition Factory::end() const
{
  return orders+numOrders;
}

Factory::OrderPosition Factory::find(Item* it) const
{
  OrderPosition pos = begin();
  while (pos != end() && pos->item != it)
    ++pos;
  return pos;
}



///Copy constructor for linked list
Factory::Factory (const Factory& b)
      : name(b.name), maxOrders(b.maxOrders), numOrders(b.numOrders)
{
     for (OrderPosition p = b.begin(); p != b.end(); ++p)
        orderItems(*p, end());
        //orderItems(end(), *p);

}



factory.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef FACTORY_H
#define FACTORY_H

#include "item.h"
#include "order.h"


class Factory {
public:
  Factory ();
  Factory (std::string name);

  ///copy constructor for linked list

  Factory (const Factory& b);

  ///end copy constructor for linked list



  // Factory name attribute
  std::string getName() const    {return name;}
  void setName (std::string nm)  {name = nm;}


  // Clear all orders for this factory
  void clearOrders();

  // Place an order for some number of items.
  // If a prior order has been placed for these, this additional
  // order adds to that prior one. The Item is also updated to reflect
  // the change in total number of that item ordered by all factories.
  void orderItems (Item* itemToOrder, int numToOrder);


  // Access to Orders (in alphabetic order by item name)
  typedef Order* OrderPosition;
  OrderPosition begin() const;
  OrderPosition end() const;

  // Find the position of the order corresponding to the
  // given item. If no such order exists, return end().
  OrderPosition find (Item*) const;


private:
  std::string name;

  // Dynamically allocated array of Order - do NOT change this
  //   choice of data structures.
  Order* orders;
  int maxOrders;
  int numOrders;
};




#endif 





I get a 'no matching function for call to 'Factory::orderItems(Order& Order*)' on line 98 of the .cpp file, in this copy constructor exactly:

factory.cpp

1
2
3
4
5
6
7
8
9
///Copy constructor for linked list
Factory::Factory (const Factory& b)
      : name(b.name), maxOrders(b.maxOrders), numOrders(b.numOrders)
{
     for (OrderPosition p = b.begin(); p != b.end(); ++p)
        orderItems(*p, end());                     //<---- here
        //orderItems(end(), *p);

}




I don't know how to fix this exactly. This ccpy constructor is being created because I need a deep copy of the linked list rather than a shallow copy because the shallow copy is giving me incorrect output. I'm just asking for a bit of advice cause I can't seem to figure out how to fix this error, if its a simple syntax error or if its something a little deeper. Thank you for any and all of your help.
Here is the function declaration

void Factory::orderItems (Item* itemToOrder, int numToOrder);

Here is the call of it

orderItems(*p, end());

Compare the declaration with the call

And please next time read error messages yourself and do not bother the forum. Error messages are issued specially for you that you read them.


Last edited on
Topic archived. No new replies allowed.