Thread: class inheritance troubles

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    14

    class inheritance troubles

    Hi, i'm having trouble finding a way around a situation like this:

    Code:
    class a{
    protected:
        vector <b> B;
        int some_int;
    };
    
    class b: public a{
    protected:
        change_int(){some_int = 5;}
    };
    obviously this wont compile as b hasn't been declared before it's use in a
    however if i predeclare it:
    Code:
    class b;
    i just get different errors. What's the best way around this?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You would have to use a pointer to B or some PIMPL idom to hide the inheritance.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You might also want to consider your design decision. Why would you want an object of b to contain multiple objects of the same type, b?
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class Troubles
    By Aliaks in forum C++ Programming
    Replies: 13
    Last Post: 06-12-2009, 02:27 AM
  2. Class Inheritance
    By leeor_net in forum C++ Programming
    Replies: 3
    Last Post: 09-24-2008, 04:37 AM
  3. Replies: 8
    Last Post: 01-13-2008, 05:57 PM
  4. Inheritance: assign base class to derived class
    By MWAAAHAAA in forum C++ Programming
    Replies: 15
    Last Post: 01-22-2007, 04:31 PM
  5. Troubles overriding a const in a derived class
    By sh0x in forum C++ Programming
    Replies: 5
    Last Post: 10-05-2001, 07:11 PM