Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 2nd, 2006, 10:46 PM   #1
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
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.
Eric the Red is offline   Reply With Quote
Old Mar 2nd, 2006, 11:23 PM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5 grumpy is on a distinguished road
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).
grumpy is offline   Reply With Quote
Old Mar 3rd, 2006, 5:17 PM   #3
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
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++.
Attached Files
File Type: zip Main.zip (2.4 KB, 11 views)
Eric the Red is offline   Reply With Quote
Old Mar 3rd, 2006, 7:47 PM   #4
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5 grumpy is on a distinguished road
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.
grumpy is offline   Reply With Quote
Old Mar 3rd, 2006, 8:04 PM   #5
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
thx it was the closing brace

Thanks so much. I just wasn't able to see that.

It works now
Eric the Red is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:14 AM.

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