. Advertisement .
..3..
. Advertisement .
..4..
I am trying to write a cpp that returns an invalid answer. I don’t know where the incorrect command is in the “does not name a type in c++.” My detail is:
class User
{
public:
MyMessageBox dataMsgBox;
};
class MyMessageBox
{
public:
void sendMessage(Message *msg, User *recvr);
Message receiveMessage();
vector<Message> *dataMessageList;
};
and I end up with the warning message:
MyMessageBox does not name a type
Pls, suggest the best answer to fix it.
The cause: I think the cause is that C++ compilers only process input once. Each class you use has to be defined first. But you use
MyMessageBox
before you define it.The solution: Before you use the prototype, you must declare it. It means that you need to swap the types as the following: