Problem referencing methods in header file

I am using Visual Studio 2010 and keep getting error C2660 for the following code. I am using 2 header files. One called cashRegister.h and one called dispenserType.h. I think all the errors are because the function on line 16 of the cashRegister.h cant see the reference to the dispenserType.h file. That is the first error that came up and if I can fix that I believe it will fix all the other erros. If anyone can shove me in the right direction I would be grateful.

ERROR CODES:

1
2
3
4
5
6
7
>c:\documents and settings\dehnb\desktop\brian's folder\juice machine vs 2\cashRegister.h(16): error C2061: syntax error : identifier 'dispenserType'
1>..\..\..\..\..\..\Desktop\Brian's Folder\Juice Machine vs 2\mainProgJuiceMachine.cpp(34): error C2660: 'cashRegister::sellProduct' : function does not take 2 arguments
1>..\..\..\..\..\..\Desktop\Brian's Folder\Juice Machine vs 2\mainProgJuiceMachine.cpp(37): error C2660: 'cashRegister::sellProduct' : function does not take 2 arguments
1>..\..\..\..\..\..\Desktop\Brian's Folder\Juice Machine vs 2\mainProgJuiceMachine.cpp(40): error C2660: 'cashRegister::sellProduct' : function does not take 2 arguments
1>..\..\..\..\..\..\Desktop\Brian's Folder\Juice Machine vs 2\mainProgJuiceMachine.cpp(43): error C2660: 'cashRegister::sellProduct' : function does not take 2 arguments
1>
1>Build FAILED. 


MAIN PROGRAM:

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
#include <iostream>
#include "cashRegister.h"
#include "dispenserType.h"
 
using namespace std;

int main()
{
    cashRegister counter;
    dispenserType orange(100, 50); 
    dispenserType apple(100, 65);
    dispenserType mango(75, 80);
    dispenserType strawberryBanana(100, 85);

    int choice;  //variable to hold the selection

    counter.showSelection(); 
    cin >> choice;

    while (choice != 9)
    {
        switch (choice)
        {
        case 1: 
            counter.sellProduct(orange, counter);//<---(43): error C2660: 'cashRegister::sellProduct' : function does not take 2 arguments
            break;
        case 2: 
            counter.sellProduct(apple, counter);//<---(43): error C2660: 'cashRegister::sellProduct' : function does not take 2 arguments
            break;
        case 3: 
            counter.sellProduct(mango, counter);//<---(43): error C2660: 'cashRegister::sellProduct' : function does not take 2 arguments
            break;
        case 4: 
            counter.sellProduct(strawberryBanana, counter);//(43): error C2660: 'cashRegister::sellProduct' : function does not take 2 arguments
            break;
        default: 
            cout << "Invalid selection." << endl;
        }//end switch

        counter.showSelection();
        cin >> choice;
    }//end while

    return 0;
}//end main 


Header file cashRegister:

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
class cashRegister
{
public:

	void showSelection();

	void sellProduct(dispenserType& product, cashRegister& pCounter); // <---- this is the problem area I think.

    int getCurrentBalance() const;
       //Function to show the current amount in the cash 
       //register.
       //Postcondition: The value of cashOnHand is returned.

    void acceptAmount(int amountIn);
       //Function to receive the amount deposited by 
       //the customer and update the amount in the register.
       //Postcondition: cashOnHand = cashOnHand + amountIn;

    cashRegister(int cashIn = 500); 
       //Constructor
       //Sets the cash in the register to a specific amount.
       //Postcondition: cashOnHand = cashIn;
       //               If no value is specified when the 
       //               object is declared, the default value 
       //               assigned to cashOnHand is 500.

private:
     int cashOnHand;     //variable to store the cash 
                         //in the register
};


Just in case the Implementation file is needed:

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
#include <iostream>
#include "dispenserType.h"
#include "cashRegister.h"

using namespace std;

int cashRegister::getCurrentBalance() const
{
    return cashOnHand;
}

void cashRegister::acceptAmount(int amountIn)
{
    cashOnHand = cashOnHand + amountIn;
}

cashRegister::cashRegister(int cashIn)
{
    if (cashIn >= 0)
        cashOnHand = cashIn;
    else
        cashOnHand = 500;
}

void cashRegister::showSelection()
{
    cout << "*** Welcome to Shelly's Juice Shop ***" << endl;
    cout << "To select an item, enter " << endl;
    cout << "1 for orange juice" << endl;
    cout << "2 for apple juice" << endl;
    cout << "3 for mango juice" << endl;
    cout << "4 for strawberry banana juice" << endl;
    cout << "9 to exit" << endl;
}//end showSelection

void cashRegister::sellProduct(dispenserType& product,cashRegister& pCounter)//
{
    int amount;  //variable to hold the amount entered
    int amount2; //variable to hold the extra amount needed

    if (product.getNoOfItems() > 0) //if the dispenser is not 
                                    //empty
    {
        cout << "Please deposit " << product.getCost()
             << " cents" << endl;
        cin >> amount;

        while (amount < product.getCost())
        {
            cout << "Please deposit another "
                 << product.getCost()- amount
                 << " cents" << endl;
            cin >> amount2;
            amount = amount + amount2;
       }

        if (amount >= product.getCost())
        {
            pCounter.acceptAmount(amount);
            product.makeSale();
            cout << "Collect your item at the bottom and "
                 << "enjoy." << endl;
        }
        else
            cout << "The amount is not enough. " 
                 << "Collect what you deposited." << endl;

        cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
             << endl << endl;
    }
    else
        cout << "Sorry, this item is sold out." << endl;
}//end sellProduct
Last edited on
it's working fine on my PC.. please check your path of .h files that you included....
Thank you for responding HiteshVaghani1. Your help is greatly appreciated.

I don't understand what you mean by "check your path of .h files you included.
How do I go about checking a path of a header file?

Also, How did you check it without the dispenserType.h file?
Last edited on
Are your files in the same folder? What you write after #include and in the quotation marks is the path name of the file. The default is to check for the file in the same folder as the file that includes it.
Last edited on
Oh, I see. Yes. All the files are in one folder. I am not having any problems with the main accessing the dispenserType.h. only the method in the other header file . when the cashRegister.h file looks for the dispencerType.h file there seems to be an issue.
Last edited on
If the code you showed for the cashRegister header file is all that is in the file, I suggest putting the dispencerType class prototype before your cashRegister class definition.
1
2
3
4
5
6
7
   //Similar to function prototype
class dispenserType;
   //Now cashRegister can use dispenserType because you promised
   //The compiler that you defined the class somewhere later
class cashRegister{
   /*...*/
};
Topic archived. No new replies allowed.