Thread: still somewhat confused with inheritance~

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    Arrow still somewhat confused with inheritance~

    Hi, guys.
    I'm somewhat confused with inheritance yet. Please check my code first, it works just fine.
    PHP Code:
    #include <iostream>
    #include <string>

    class Vehicle
    {
      public:
        
    Vehicle(stringintint);
        
    Vehicle(){cout << "undefined vehicle" << endl;};
        
    void profile();
      private:
        
    string name;
        
    int wheel;
        
    int speed;
    };
    Vehicle :: Vehicle(string sint wint sp)
    {
      
    name=s;
      
    wheel=w;
      
    speed=sp;
      
    cout << "the name of the vehicle present is: " << name << endl;
      
    cout << "it has " << << " wheels." << endl;
      
    cout << "its speed is " << sp << " km/h." << endl;
    }
    void Vehicle :: profile()
    {
      
    cout << "welcome here, I'll introduce the vehicle later." << endl;
    }

    class 
    Car : public Vehicle
    {
      public:
        
    Car(stringintintint);
        
    Car(){ cout << "undefined car" << endl; };
      private:
        
    int price;
    };
    Car :: Car(string sint wint spint p) : Vehicle(swsp)
    {
      
    price=p;
      
    cout << "its price is " << price << " dollars." << endl;
    }

    void main()
    {
      
    Car myCar1;
      
    cout << endl;
      
    Car myCar2("bicycle"2150);

    Now, 2 questions are waiting your suggestions:
    1 when I create a object with the Car class, the old constructor with base class Vehicle are called first. we could see it from the output. Could I get ride of those which belong to base class and display only the contents of derived class ?
    2 the first constructor of derived class has 4 arguments, and 3 of them belong to the base class Vehicle, so I write something like this: : Vehicle(s, w, sp) but what about when we need of part of those arguments ? for example, we just want pass s and sp from the old class. I tried : Vehicle(s, sp) but got an error.
    Last edited by black; 06-30-2002 at 10:39 PM.
    Never end on learning~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to C++ and confused by boolean and ifs and else
    By jconner in forum C++ Programming
    Replies: 10
    Last Post: 08-02-2006, 03:29 AM
  2. Confused
    By jeev2005 in forum C Programming
    Replies: 5
    Last Post: 06-01-2006, 02:04 PM
  3. why wont this compile?!? :confused:
    By jdude in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2004, 01:13 AM
  4. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM
  5. Extern Question, really confused
    By SourceCode in forum C Programming
    Replies: 10
    Last Post: 03-26-2003, 11:11 PM