DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2005

    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:

    class myApp : public CWinApp
    //and so on...

    I added to this definition a few member variables and functions this way:

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

    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:

    #ifndef _MY_CLASS_
    #define _MY_CLASS_
    class myClass{
    	int myValue;
    	myClass(){myValue = 0;}
    	int GetValue();
    #end if
    #include "myClass.h"
    int myClass::GetValue(){
    	return myValue;
    Now, when I try to compile I get 3 errors:

    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
    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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

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

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.