inheritance

This is a discussion on inheritance within the C++ Programming forums, part of the General Programming Boards category; I'm experimenting with lists and the passing of nodes and I ran across a problem. The problem is this: I ...

  1. #1
    Unregistered
    Guest

    inheritance

    I'm experimenting with lists and the passing of nodes and I ran across a problem. The problem is this: I can access the public members of the derived class, but I cannot access the public members of the base class. I'll post a couple of classes and the one function to keep things simple. Any ideas would be appreciated.

    CLASSES:

    class terrain {
    private:
    int terrain_type;
    public:
    terrain() { terrain_type = 0; }
    int GetTerrain() { return terrain_type; }
    void SetTerrain( int t ) { terrain_type = t; }
    };

    class world : public resources, terrain {
    private:
    int x, y;
    public:
    world(){ x = y = 0; }
    friend ostream &operator<<( ostream &, world );
    list<world>::iterator FindProvince( list<world> &, int, int );
    int Getx() { return x; }
    int Gety() { return y; }
    void Setxy( int a, int b ) { x = a; y = b; }
    void TraverseMap( list<world> & );
    };

    void InitializeProvince( world &province, int x, int y )
    {

    int t_type;

    province.Setxy(x,y);

    cout << "Enter a t_type: \n";

    cin >> t_type;

    province.SetTerrain( t_type );

    cout << "T: " << province.GetTerrain() << endl;

    }


    Note that I can use Setxy() but I cannot use GetTerrain() even thought it is a public member of class terrain.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    3
    I'm not sure but try putting public before terrain in the world class definition.

    class world : public resources, public terrain {
    ...
    };

  3. #3
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    edit - above is the reason
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 04:03 PM
  2. Virtual inheritance
    By 6tr6tr in forum C++ Programming
    Replies: 13
    Last Post: 05-07-2008, 12:20 PM
  3. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  4. inheritance and performance
    By kuhnmi in forum C++ Programming
    Replies: 5
    Last Post: 08-04-2004, 01:46 PM
  5. Inheritance vs Composition
    By Panopticon in forum C++ Programming
    Replies: 11
    Last Post: 01-20-2003, 04:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21