Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   base type has incomplete type (http://www.programmingforums.org/showthread.php?t=8690)

Eric the Red Mar 2nd, 2006 10:46 PM

base type has incomplete type
 
Can someone please tell me why i get the error "base class has incomplete type"? I'm just learning my way through c++ so bear with me.

:


class Vehicle
{
public:
    //Vehicle(){intSpeed = 1;}
    //Move();
    int GetSpeed() {return itsSpeed;}
    void Move(){std::cout << " Vehicle is moving at " << itsSpeed << " Km per hour" ;}
    void Turn(){std::cout << "Vehicle is turning left at " << itsTurnSpeed
                    << " degrees per second";}
    void Respond(){std::cout << " Vehicle responding\n";}
    //////
    void Speeding() { if ( itsSpeed > (30))
    {
        std::cout << "You are over the speed limit, please slow down./n Your going" << itsSpeed << "Kilometers/ hour\n";
    }
    else
    {
        std::cout << "Your under the speed limit. Your at " << itsSpeed << " KM/H at the moment.\n";
    ;}
    //// 
   
protected:
  int itsSpeed;
  int itsTurnSpeed;
};

/////////////////////////////////////////////////////////////////////////////////

class Car: public Vehicle
{
public:
    Car() {itsSpeed = 20;}
    //~Car();
    void SetSpeed (int speed) { itsSpeed = speed;}
    void Speed() { itsSpeed = itsSpeed + 2;}
    void Respond(){std::cout << " I'm a car \n";}
private:
    int itsType;
   
};

///////////////////////////////////////

class Boat: public Vehicle
{
public:
    Boat() {itsSpeed = 5;}
    //~Car();
    void SetSpeed (int speed) { itsSpeed = speed;}
    void Speeding();
    void Speed() { itsSpeed = itsSpeed + 1;}
    void Respond(){std::cout << " I'm a boat \n";}
private:
    int itsType;
   
};


Next i'm learning virtual functions so i need to get this down first. Any help would be greatly appreaciated. If you need main() just let me know. Though I doupt it will help since main() isn't giving me the error, but one of the classes are.

grumpy Mar 2nd, 2006 11:23 PM

You haven't given enough information. My guess is that you have declared your classes in different header files, with a dependency between them. For example, you might have Vehicle.h which declares Vehicle, Boat.h which declares Boat. If Boat.h or Car.h do not #include "Vehicle.h" that might explain your error message.

You also need to #include <iostream> before any usage of std::cout. That might also account for your error.

Unrelated to your problem, but both your derived classes have an int member named itsType. It may be appropriate, from a design perspective, for your base class to provide that member. Also, from a design perspective, it may be appropriate for your base class to provide some virtual methods that derived classes override, rather than having your derived classes introduce new characteristics.

And, lastly, NEVER NEVER NEVER use comments of the form
:

///////////////////////
There are serious gotchas with that style of comment (eg if you hit a shift key at the wrong time while holding down a / key, you can introduce a digraph or trigraph and comment out following lines without realising it).

Eric the Red Mar 3rd, 2006 5:17 PM

1 Attachment(s)
Here's the simple project Hope this makes it more clear.

And please tell me if i've done everything properly. I'm using dev-C++.

grumpy Mar 3rd, 2006 7:47 PM

I just got bored and fed your code (from the first post) into a compiler.

It has a missing closing brace. Add one after the if/else clause for Vehicle::Speeding() function, and before the protected keyword.

And refer to my previous post for what you need to do with Boat.h and Car.h that you have in your zip file.

Eric the Red Mar 3rd, 2006 8:04 PM

thx it was the closing brace
 
Thanks so much. I just wasn't able to see that.

It works now :D


All times are GMT -5. The time now is 12:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC