Value of data members

This is a discussion on Value of data members within the C++ Programming forums, part of the General Programming Boards category; I'm not sure what I am doing!? I am trying to understand inheritance and want to see what values get ...

  1. #1

    Question Value of data members

    I'm not sure what I am doing!?
    I am trying to understand inheritance and want to see what values get passed by using my main().

    I'm not too sure if my argument constructors are correct.

    #include <iostream.h>

    class Class_A
    int A_private;
    int A_protected;
    Class_A(int, int);
    void A_Pub_Func();

    class Class_B : public Class_A
    int B_private;
    int B_protected;
    Class_B(int, int);
    void B_Pub_Func();

    class Class_C : private Class_A
    int C_private;
    int C_protected;
    Class_C(int, int);
    void C_Pub_Func();

    class Class_D : public Class_B
    int D_private;
    int D_protected;
    Class_D(int, int);
    void D_Pub_Func();

    class Class_E : public Class_C
    int E_private;
    int E_protected;
    Class_E(int, int);
    void E_Pub_Func();

    Class_A::Class_A(int a, int b) {
    A_private = a;
    A_protected = b;

    Class_B::Class_B(int a, int b) {
    B_private = a;
    B_protected = b;

    Class_C::Class_C(int a, int b) {
    C_private = a;
    C_protected = b;

    Class_D::Class_D(int a, int b) {
    D_private = a;
    D_protected = b;

    Class_E::Class_E(int a, int b) {
    E_private = a;
    E_protected = b;

    void main()
    Class_A a_object(1,1);
    Class_B b_object(2,2);
    Class_C c_object(3,3);
    Class_D d_object(4,4);
    Class_E e_object(5,5);

  2. #2
    Registered User raimo's Avatar
    Join Date
    Jun 2002
    If Class_A is a superclass of Class_B, then you should write B:s constructor like this:
    Class_B::Class_B(int a, int b) : Class_A(a,b) { 
      B_private = a; 
      B_protected = b; 
    ..because you have no default constructor in Class_A.
    Do this to all inherited classes.

    Btw, you should write int main () instead of void main(). This is the standard way to do it. Find more with google.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. member functions can't see private data members
    By ichijoji in forum C++ Programming
    Replies: 2
    Last Post: 11-22-2006, 02:36 PM
  3. Replies: 4
    Last Post: 06-14-2005, 06:45 AM
  4. Accessing private data members
    By maloy in forum C++ Programming
    Replies: 11
    Last Post: 10-04-2002, 03:48 PM
  5. C Programming Question
    By TK in forum A Brief History of
    Replies: 13
    Last Post: 07-04-2002, 08:11 PM

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