Results 1 to 2 of 2

Thread: Error C2504???

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Wink

    Im making {or trying to make} a car simulator in C++
    It is a console application, but i keep getting this error
    C2504. Undefined base class.

    #include "Odometer.h"


    //this is the base class

    class Car
    {
    public:
    // class constructor to initilize objects as they are created
    // and to ensure that data members contain vaild values
    Car(bool B = false, bool A = false)
    {
    m_brake(B);
    m_accelerator(A);
    }



    void set_temp(); // member functions prototype
    void start_engine();
    void kill_engine();
    void set_gas();
    void set_brake();
    void change_gears();
    void change_direction();

    int get_speed();
    int get_fuel();
    int get_distance();
    int get_RPM();
    int get_temp();

    char m_brake; // data members
    char m_accelerator;
    };

    // derived class in another file

    // class defination for our odometer


    class Odometer: public Car
    { // error is generated here when compiled Do i have to
    public: // use the extern keyword to specify external
    // linkage ?????? That's the only thing i can
    // think of


    Odometer(long dt = 0) // class constructor
    {
    m_distance_trav(dt);
    }

    int reading(int cur_speed); //function prototype



    long m_distance_trav;
    };


    // thanks all!!!














    };

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    where your error was, did you have a space between "Odometer" and the colon? -

    Code:
    Odometer : public Car
    rather than
    Code:
    Odometer: public Car
    I think it's compiler dependent, but you seem to be using MSVC++.

    If you have your Car class defined in Car.h, with the implementation in Car.cpp, then put Odometer in Odometer.h, with it's implementation in Odometer.cpp. Then, in Odometer.h, #include "Car.h". this should solve your problem.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width