By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

How can we refer superclass constructor from subclass in c++ ???

P: 40
1..In java we can refer superclass constructor by super()keyword,but
Where as in c++ how can we refer to that???.

In java the following code is used for referring superclass constructor..
Expand|Select|Wrap|Line Numbers
  1. class cal1
  2.     {
  3.       private int a,b,c;
  4.       public cal1(int i,int j)
  5.       {
  6.       a=i;
  7.       b=j;
  8.      }
  9.      public void add()
  10.      {
  11.       c=a+b;
  12.       System.out.println("addition is "+c);
  13.      }
  14.    }
  15. class cal2 extends cal1
  16. {
  17.   private int a1,b1,c1;
  18.   public cal2(int i1,int j1,int k1,int l1)
  19.   {
  20.    super(i1,j1);
  21.    a1=k1;
  22.    b1=l1;
  23.   }
  24.   public void mul()
  25.   {
  26.    c1=a1*b1;
  27.    System.out.println("mul is "+c1); 
  28.   }
  29. }
Mar 20 '07 #1
Share this Question
Share on Google+
1 Reply


dmjpro
100+
P: 2,476
try this .....

Expand|Select|Wrap|Line Numbers
  1. class A
  2. {
  3. public:
  4.     A(int i){}
  5. };
  6.  
  7. class B : public A
  8. {
  9. public:
  10.     B(int i):A(i)
  11.     {}
  12. }
  13.  
welcome again
Mar 20 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.