Can somebody take a look at these and tell me why the boat class will not inherit from the transport class, i keep getting these errors, i have the two classes in the same source file folder, ive tried putting them both together with no luck either..

help !!

 error LNK2005: _main already defined in boat_class.obj
 error LNK1169: one or more multiply defined symbols found

code:

#include<iostream>
using namespace std;
class transport {
private:
    float passengers;
    float fuelcap;
    float mpg;

    // can be accessed only by members of their class and not other parts of program.

public:

    // all variables and functions can be accessed by other parts of the program.
float range;

void getfuelcap (float);
void getpassengers (float);
void getmpg (float);

void setrange (float);

void display_transport();

};
int main (){

transport minivan;

    float passengers;
    float fuelcap;
    float mpg;
    float range;

    cout<<"enter the pasengers of the vehicle";
    cin>>passengers;
    cout<<"enter the fuel capacity of the vehicle";
    cin>>fuelcap;
    cout<<"enter the mpg of the vehicle";
    cin>>mpg;"\n";

    minivan.getpassengers(passengers);
    minivan.getfuelcap(fuelcap);
    minivan.getmpg (mpg);
    minivan.setrange (range);

    minivan.display_transport ();

return 0;
}
void transport :: getpassengers (float thepassengers)
{
passengers = thepassengers;
}
void transport :: getfuelcap(float thefuelcap)
{
fuelcap = thefuelcap;
}
void transport :: getmpg(float thempg)
{
mpg = thempg;
}
void transport :: setrange(float therange)
{
 range = (mpg * fuelcap);
}
void transport :: display_transport()
{
    cout<<"the number of passengers for this vehicle is " << passengers <<"\n";
    cout<<"the fuel capacity of the vehicle is " << fuelcap <<"\n";
    cout<<"the mpg of the vehicle is " << mpg <<"\n";cout<<endl;
    cout<<"the range for the mini van is " << range <<"\n";
}

code:

#include <iostream>
using namespace std;     // this is the derived class it inherits from the base class vehicle.
class boat {

public:

int weight;
int length;
int knots;

    void getweight (int);
    void getlength (int);
          void getknots (int);

    void display_boat ();

};
class transport : public boat  {
public :
};
int main (){

 boat cruiser;

    int length;
    int weight;
    int knots;

    cout<<"enter the length of the boat";
    cin>>length;
    cout<<"enter the weight of the boat";
    cin>>weight;
    cout<<"enter the speed of the boat";
    cin>>knots;

    cruiser.getlength(length);
    cruiser.getweight(weight);
    cruiser.getknots (knots);

    cruiser.display_boat ();


return 0;
}

void boat :: getlength(int thelenght)
{
length = thelenght ;
}
void boat :: getweight(int theweight)
{
weight = theweight ;
}
void boat :: getknots(int theknots)
{
knots = theknots ;
}

void boat :: display_boat ()

{
  cout<<"the weight of boat is " << weight <<"\n";
  cout<<"the lenght of the boat is " << length <<"\n";
  cout<<"the knots of the about is " << knots <<"\n";
}

You aren't telling boat to inherit from transport. Read this.

Also, there must only be one (1) main() in your entire program. It can not be part of any class, it must be globally-scoped.

This won't work:

class someClass {
 int main() {
   return 0;
 }
};

Neither will this:

class someClass {
};

int main() {
  return 0;
}

class anotherClass {
};

int main() {
  return 0;
}

It must be this:

class someClass {
};

class anotherClass {
};

int main() {
  return 0;
}

This is inheritance:

class base {
};

class derived : public base {
};

int main() {
  return 0;
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.