class inheritance troubles

This is a discussion on class inheritance troubles within the C++ Programming forums, part of the General Programming Boards category; Hi, i'm having trouble finding a way around a situation like this: Code: class a{ protected: vector <b> B; int ...

  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
    Posts
    22,915
    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,531
    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 in reply to you, it is likely you deserve it. Suck it up, sunshine, 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, 03:27 AM
  2. Class Inheritance
    By leeor_net in forum C++ Programming
    Replies: 3
    Last Post: 09-24-2008, 05: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, 08:11 PM

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