Hi, I rarely use C++, so when I have to, I'm trying to stick to the basics.
I am trying to make some sense of MFC by writing small GUI applications. Coming from a VB background, it seemed like a good point to start.
This is what I did: I started a new MFC project in Visual C++ 6 and let the wizard create it's standard classes. Whenever I'm "playing" with MFC, I build up from here.
The MFC wizard created this class for me:
Code:class myApp : public CWinApp { public: myApp(); //and so on...
I added to this definition a few member variables and functions this way:
then:Code:class myApp : public CWinApp { private: int myVar; public: myApp(); int myFunction(); //and so on...
All this compiled fine and ran as expected.Code:int myApp::myFunction(){ //do some stuff }
Then I tried to create a class. I added 2 files to the project, myClass.h and myClass.cpp:
Now, when I try to compile I get 3 errors:Code://myClass.h #ifndef _MY_CLASS_ #define _MY_CLASS_ class myClass{ private: int myValue; public: myClass(){myValue = 0;} int GetValue(); } #end if //myClass.cpp #include "myClass.h" int myClass::GetValue(){ return myValue; }
Every book and online tutorial on C++ that I could find assure me this is OK, yet it doesn't compile. The compiler only accepts inline member functions, like the constructor for myClass.Code:error C2628: 'myClass' follwed by int is illegal (did you forget a ';' ?) error C2556: 'class myClass __thiscall myClass::GetValue(void)' : overloaded function differs only by return type from 'long __thiscall myClass::GetValue(void)' see declaration of 'getValue' error C2371: 'GetValue' : redefinition: different basic types
What am I missing here? Is there some Visual C++ setting that I am overlooking? Why is it accepting my new functions when I add them to the wizard generated class, but not when I create my own class?
And, speaking of the wizard, was it Ok for me to add functions like that to it's class, or was I just lucky to get it to work? I noticed it also added a number of macros and comments I didn't understand to that class.


Reply With Quote


Bookmarks