![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5
![]() |
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 /////////////////////// |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
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++. |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5
![]() |
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: peeding() 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. |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
thx it was the closing brace
Thanks so much. I just wasn't able to see that.
It works now ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|