1

私はこのコードを持っています

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

ただし、コンストラクター委任を使用しない場合は、正しく機能します。

なんで?

4

1 に答える 1

5

GCC 4.5 はコンストラクターの委譲をサポートしていません。GCC 4.7 を使用する必要があります。http://gcc.gnu.org/projects/cxx0x.htmlを参照してください。

于 2013-01-23T10:19:09.567 に答える