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.
#include <iostream>
#include "cashRegister.h"
#include "dispenserType.h"
usingnamespace 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
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
};
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.
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.
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{
/*...*/
};