Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

constructor inheritance with C++11 compiler is generating error

Tags:

c++

gcc

c++11

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

like image 545
user3282758 Avatar asked Apr 09 '26 10:04

user3282758


2 Answers

Inheriting constructors were not supported in GCC until version 4.8.

Source

like image 89
ildjarn Avatar answered Apr 11 '26 00:04

ildjarn


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)

like image 23
NathanOliver Avatar answered Apr 10 '26 23:04

NathanOliver