Can't make a simple Project work

This is a discussion on Can't make a simple Project work within the C++ Programming forums, part of the General Programming Boards category; Hi there. This is one of my first projects in C++ and I'm stack in the beggining! I don't know ...

  1. #1
    csd@auth
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    71

    Unhappy Can't make a simple Project work

    Hi there. This is one of my first projects in C++ and I'm stack in the beggining!
    I don't know what could be wrong.
    compiler errors:new types may not be defined in a return type
    return type specification for constructor invalid
    build error [main.o] error1


    main.cpp
    Code:
    #include "geo.h"
    #include <cstdlib>
    #include <iostream>
    using std::cout;
    using std::endl;
    using std::cin ;
    int main()
    {
    
      
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    geo.h
    Code:
    #ifndef myheader_h
    #define myheader_h
    
    class MyClass 
               {
                private:
                       int a,b;        
                        
                public :
                   MyClass();
                   MyClass(int k, int l);
                   void func(void);
                }
    
    MyClass::MyClass()
       {
           a=b=0;
       }
    
    MyClass::MyClass(int k, int l)
     {
      a=k;
      b=l;
     }
    void MyClass::func(void)
     {
        //cout<<"do something";
     }
    #endif

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Right off I see that you didn't put a closing semicolon at the end of your class definition - should be
    Code:
    class MyClass 
               {
                    // stuff
                }; // semicolon here

  3. #3
    csd@auth
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    71
    Thaks a lot robatino. It was so simple but I'm sure i would not find it.
    I guess this is a common mistake every newbie does.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    also function definitions (bodies) should go to the cpp file
    header should contain only class definition and inline functions
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    I'm still a bit iffy on classes, but i think you need to explictily call your destructor since you made your own constructor.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,305
    i think you need to explictily call your destructor since you made your own constructor
    That's not true. Even if you meant "write your own destructor", that still is not true since the compiler generated destructor will suffice for primitive member variables.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-26-2006, 09:23 AM
  2. how do I make fstream's >> work for my class?
    By MathFan in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2005, 01:01 PM
  3. I haev to make this work!
    By SledMan2002 in forum C Programming
    Replies: 3
    Last Post: 11-04-2002, 05:26 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. Replies: 1
    Last Post: 11-06-2001, 02:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21