MFC newbie question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: MFC newbie question

  1. #1
    Join Date
    Nov 2005
    Posts
    27

    MFC newbie question

    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:

    Code:
    class myApp : public CWinApp
    {
    private:
    	int myVar;
    
    public:
    	myApp();
    
                 int myFunction();
    
    //and so on...
    then:

    Code:
    int myApp::myFunction(){
    //do some stuff
    }
    All this compiled fine and ran as expected.

    Then I tried to create a class. I added 2 files to the project, myClass.h and myClass.cpp:

    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;
    }
    Now, when I try to compile I get 3 errors:

    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
    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.

    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.

  2. #2
    Join Date
    Nov 2005
    Posts
    27
    Nevermind, I found it. :o

Similar Threads

  1. Replies: 1
    Last Post: 01-18-2003, 02:09 PM
  2. newbie question
    By Tim Wilkinson in forum Java
    Replies: 0
    Last Post: 04-26-2002, 05:40 AM
  3. NewBie question
    By Boosman in forum ASP.NET
    Replies: 1
    Last Post: 01-05-2002, 05:29 AM
  4. Newbie question: Trusted Connection and IBuySpy sample
    By Marco Mangiante in forum Database
    Replies: 0
    Last Post: 12-04-2001, 01:01 PM
  5. newbie easy question
    By bbp in forum VB Classic
    Replies: 1
    Last Post: 11-02-2000, 03:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center