I am trying to compile the following code (taken directly from wikipedia) to understand constructor inheritance in C++11 :
class BaseClass {
public:
BaseClass(int value);
};
class DerivedClass : public BaseClass {
public:
using BaseClass::BaseClass;
};
I am compiling this file as follows :
/usr/bin/g++-4.7 -c -std=c++11 file.cpp
But this is giving the following error :
error: ‘BaseClass::BaseClass’ names constructor
I do not know where am I going wrong
Inheriting constructors were not supported in GCC until version 4.8.
Source
According to C++0x/C++11 Support in GCC inheriting constructors were not available until gcc 4.8.
I can confirm that with http://gcc.godbolt.org/ as
class BaseClass {
public:
BaseClass(int value);
};
class DerivedClass : public BaseClass {
public:
using BaseClass::BaseClass;
};
int main()
{
}
Compiles just fine with gcc 4.8.1(Live Example)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With