C2061
-
Hi! I've defined two classes. I've used the object of the first class inside the second class and the object of the second class inside the first class. I've forward declared both the classes. But I got the following error error C2061: syntax error : identifier 'initialMenu' My Code is:
class InitialMenu; //forward declaration
class PlayMenu;class InitialMenu : public IEventReceiver
{
private:
SAppContext &Context;
PlayMenu *playMenu;
public:
InitialMenu(SAppContext &context) : Context(context)
{
}virtual bool OnEvent(const SEvent& event) { playMenu = new PlayMenu(Context); return true; }
};
class PlayMenu : public IEventReceiver
{
private:
SAppContext &Context;
InitialMenu* initialMenu;
public:
PlayMenu(SAppContext &context) : Context(context)
{
}
virtual bool OnEvent(const SEvent& event)
{
initialMenu = new initialMenu(Context);
return true;
}
};How to resolve this error?
-
Hi! I've defined two classes. I've used the object of the first class inside the second class and the object of the second class inside the first class. I've forward declared both the classes. But I got the following error error C2061: syntax error : identifier 'initialMenu' My Code is:
class InitialMenu; //forward declaration
class PlayMenu;class InitialMenu : public IEventReceiver
{
private:
SAppContext &Context;
PlayMenu *playMenu;
public:
InitialMenu(SAppContext &context) : Context(context)
{
}virtual bool OnEvent(const SEvent& event) { playMenu = new PlayMenu(Context); return true; }
};
class PlayMenu : public IEventReceiver
{
private:
SAppContext &Context;
InitialMenu* initialMenu;
public:
PlayMenu(SAppContext &context) : Context(context)
{
}
virtual bool OnEvent(const SEvent& event)
{
initialMenu = new initialMenu(Context);
return true;
}
};How to resolve this error?
You should split the class declarations into header files and class definitions into CPP files.
«_Superman_»
I love work. It gives me something to do between weekends. -
Hi! I've defined two classes. I've used the object of the first class inside the second class and the object of the second class inside the first class. I've forward declared both the classes. But I got the following error error C2061: syntax error : identifier 'initialMenu' My Code is:
class InitialMenu; //forward declaration
class PlayMenu;class InitialMenu : public IEventReceiver
{
private:
SAppContext &Context;
PlayMenu *playMenu;
public:
InitialMenu(SAppContext &context) : Context(context)
{
}virtual bool OnEvent(const SEvent& event) { playMenu = new PlayMenu(Context); return true; }
};
class PlayMenu : public IEventReceiver
{
private:
SAppContext &Context;
InitialMenu* initialMenu;
public:
PlayMenu(SAppContext &context) : Context(context)
{
}
virtual bool OnEvent(const SEvent& event)
{
initialMenu = new initialMenu(Context);
return true;
}
};How to resolve this error?
-
Hi! I've defined two classes. I've used the object of the first class inside the second class and the object of the second class inside the first class. I've forward declared both the classes. But I got the following error error C2061: syntax error : identifier 'initialMenu' My Code is:
class InitialMenu; //forward declaration
class PlayMenu;class InitialMenu : public IEventReceiver
{
private:
SAppContext &Context;
PlayMenu *playMenu;
public:
InitialMenu(SAppContext &context) : Context(context)
{
}virtual bool OnEvent(const SEvent& event) { playMenu = new PlayMenu(Context); return true; }
};
class PlayMenu : public IEventReceiver
{
private:
SAppContext &Context;
InitialMenu* initialMenu;
public:
PlayMenu(SAppContext &context) : Context(context)
{
}
virtual bool OnEvent(const SEvent& event)
{
initialMenu = new initialMenu(Context);
return true;
}
};How to resolve this error?
Without knowing which line the error happened at it's a bit hard working out why you're getting that error. Having said thay if you implement your classes the way you do within the same translation unit you'll never get it to work - you've got a cyclic depenedency between the two clases. Each has to know the size of the other to be able to create instances of the other. Split them up into pairs of .h and .cpp files and it'll have a better chance of working. Oh, and remember to implement destructors or use some sort of resource management class instead of the pointers. And beware of any class that calls itself a context (or manager) they're usually global state in disguise. Cheers, Ash
-
If you look at the line that the error refers to you may notice the incorrect constructor call thus:
initialMenu = new initialMenu(Context);
It's time for a new signature.
-
Good spot - I'm surprised that he's not getting an error message about trying to create a PlayMenu when the class has been declared but not defined but I completely missed the typo. Cheers, Ash
-
Hi! I've defined two classes. I've used the object of the first class inside the second class and the object of the second class inside the first class. I've forward declared both the classes. But I got the following error error C2061: syntax error : identifier 'initialMenu' My Code is:
class InitialMenu; //forward declaration
class PlayMenu;class InitialMenu : public IEventReceiver
{
private:
SAppContext &Context;
PlayMenu *playMenu;
public:
InitialMenu(SAppContext &context) : Context(context)
{
}virtual bool OnEvent(const SEvent& event) { playMenu = new PlayMenu(Context); return true; }
};
class PlayMenu : public IEventReceiver
{
private:
SAppContext &Context;
InitialMenu* initialMenu;
public:
PlayMenu(SAppContext &context) : Context(context)
{
}
virtual bool OnEvent(const SEvent& event)
{
initialMenu = new initialMenu(Context);
return true;
}
};How to resolve this error?
-
I think your spelling wrong:
virtual bool OnEvent(const SEvent& event) { initialMenu = new initialMenu(Context); return true; } virtual bool OnEvent(const SEvent& event) { initialMenu = new InitialMenu(Context); return true; }
-
Hi! I've defined two classes. I've used the object of the first class inside the second class and the object of the second class inside the first class. I've forward declared both the classes. But I got the following error error C2061: syntax error : identifier 'initialMenu' My Code is:
class InitialMenu; //forward declaration
class PlayMenu;class InitialMenu : public IEventReceiver
{
private:
SAppContext &Context;
PlayMenu *playMenu;
public:
InitialMenu(SAppContext &context) : Context(context)
{
}virtual bool OnEvent(const SEvent& event) { playMenu = new PlayMenu(Context); return true; }
};
class PlayMenu : public IEventReceiver
{
private:
SAppContext &Context;
InitialMenu* initialMenu;
public:
PlayMenu(SAppContext &context) : Context(context)
{
}
virtual bool OnEvent(const SEvent& event)
{
initialMenu = new initialMenu(Context);
return true;
}
};How to resolve this error?
dear radha, can you please consult MSDN and google, before posting your query here!, if you type C2061 in MSDN, it will let you know, why it's throwing the error!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You