You are here:

C++/Constructors

Advertisement


Question
Hi,

i want to inherit the base class constructors in to my derive class but its failing.

struct B1 {
  B1(char);
};
struct B2 {
  B2(double);
  B2(int);
};
struct D1 : B1, B2
{
   using B1::B1;
   
   using B2::B2;
  
 
};

int main()
{
   
 D1 d(2);  //even though i didnt mention the Dervie class constructor i have to make use of the base class one.  
 return 0;
   
}



can you please let me know the problem in this code.

Regards,
sireesh.

Answer
As per the current International Standard for C++, base class constructors can not be inherited (made available to derived classes via using declarations). This is a feature that will be available in the forthcoming C++ standard - informally called C++0X.
see:
http://www.research.att.com/~bs/C++0xFAQ.html#inheriting
http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=445
http://en.wikipedia.org/wiki/C++0x#Object_construction_improvement

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.