3

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

1

2 Answers 2

4

Inheriting constructors were not supported in GCC until version 4.8.

Source

Sign up to request clarification or add additional context in comments.

Comments

3

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.