我不能像在main()中那样调用类并在函数中使用它。这个代码有什么问题,我正在使用visual studio 2015社区,错误是: -
Error C2653 'CALL': is not a class or namespace
Error C3861 'calling': identifier not found
以下是代码:
void menu()
{
int i, j, user;
for (i = 1; i <= 5; i++)
{
cout << "* *";
}
cout << " WELCOME TO CRAZY MATH ";
for (i = 1; i <= 5; i++)
{
cout << "* *";
}
cout << "\n\nPlease choose an option...\n_______________________________________\n" << endl;
cout << "press 1 for basic math calculator\npress 2 for TABLES\npress 3 for a random number" << endl;
cout << "press 4 for matrix calculator\npress 5 for programmer's converter\n\npress 0 to exit\n" << endl;
//various options provided to the user, more will be added soon...
cin >> user; //gets input from the user
CALL objk; // declared class //but cannot use it shows error
objk.calling(user);
}
// here lies the class call
class CALL
{
private:
int user;
public:
void calling(int user)
{
if (user == 1) // for bas_cal
{
bas_math m1;
m1.calc();
}
else if (user == 3) // random numbers
{
srand(time(0));
cout << "__________________________________\n\nthe random number is: " << rand() % 21;
}
else if (user == 2) // tables
{
tables tab;
tab.table();
}
else if (user == 4) //matrix
{
MATRIX mat;
mat.matrix();
}
else if (user == 0) //exit
{
EXIT e;
e.exi();
}
}
};