"Is not a direct base of " GCC 4.5.2 编译器错误

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

本文关键字:错误 编译器 GCC of Is not direct base      更新时间:2023-10-16

我有这个代码

#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;

并在使用 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>

但是,如果我不使用构造函数委托,则可以正常工作。

为什么?

GCC

4.5 不支持构造函数委托;您需要使用 GCC 4.7;请参阅 http://gcc.gnu.org/projects/cxx0x.html。