Thread: two-argument constructor

  1. #1
    Unregistered
    Guest

    Question two-argument constructor

    How would I write a two-argumet constructor for Class_E. I want to assign the first argument to the private data member and the second argument to the protected data member.

    #include <iostream.h>

    class Class_A
    {
    private:
    int A_private;
    protected:
    int A_protected;
    public:
    Class_A(int, int);
    void A_Pub_Func();
    };

    class Class_B : public Class_A
    {
    private:
    int B_private;
    protected:
    int B_protected;
    public:
    Class_B(int, int);
    void B_Pub_Func();
    };

    class Class_C : private Class_A
    {
    private:
    int C_private;
    protected:
    int C_protected;
    public:
    Class_C(int, int);
    void C_Pub_Func();
    };

    class Class_D : public Class_B
    {
    private:
    int D_private;
    protected:
    int D_protected;
    public:
    Class_D(int, int);
    void D_Pub_Func();
    };

    class Class_E : public Class_C
    {
    private:
    int E_private;
    protected:
    int E_protected;
    public:
    Class_E(int, int);
    void E_Pub_Func();
    };

    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
    Unregistered
    Guest
    that would be the constructor:

    <code>
    Class_E::Class_E(int a, int b) {
    E_private = a;
    E_protected = b;
    }
    </code>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. default constructor == constructor without argument?
    By cyberfish in forum C++ Programming
    Replies: 6
    Last Post: 04-15-2009, 03:25 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Assignment operator in a constructor argument
    By chadwickstein in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2006, 04:08 PM
  4. calling default instead of argument constructor, why?!
    By cppn00b in forum C++ Programming
    Replies: 6
    Last Post: 01-30-2005, 04:24 AM
  5. Nested loop frustration
    By caroundw5h in forum C Programming
    Replies: 14
    Last Post: 03-15-2004, 09:45 PM