Thread: Can't make a simple Project work

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    also function definitions (bodies) should go to the cpp file
    header should contain only class definition and inline functions
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 08: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, 12: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