Tio Pepe
Tio Pepe

Reputation: 3089

"Is not a direct base of " gcc 4.5.2 compiler error

I have this code

#include <vector>
#include <array>

template <typename T>
struct Vertice
{
    T elements_[4];

    Vertice(const T & x, const T & y, const T & z)
    {
        elements_[0] = x;
        elements_[1] = y;
        elements_[2] = z;
        elements_[3] = T(1);
    }
    Vertice() : Vertice(T(0), T(0), T(0)) {}
};

typedef Vertice<float> VerticeF;
std::array<VerticeF, 5> v2;

and returns following error when compiling with gcc 4.5.2:

$ g++ -o tutorial tutorial.cpp -std=gnu++0x
tutorial.cpp: In constructor ‘Vertice<T>::Vertice() [with T = float]’:
/usr/include/c++/4.5/tr1_impl/array:50:5:   instantiated from here
tutorial.cpp:28:41: error: type ‘Vertice<float>’ is not a direct base of ‘Vertice<float>

However, if I don't use constructor delegation, works properly.

Why?

Upvotes: 1

Views: 3244

Answers (1)

piwi
piwi

Reputation: 5336

GCC 4.5 does not support constructor delegation; you need to use GCC 4.7; see http://gcc.gnu.org/projects/cxx0x.html.

Upvotes: 5

Related Questions