我有这个代码

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

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

为什么?

最佳答案

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

关于c++ - “Is not a direct base of ” gcc 4.5.2编译器错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14477221/

10-14 16:26