小编use*_*715的帖子

GCC/VS2008:模板化基类从自身派生时函数调用的不同行为

以下代码适用于Visual Studio 2008,但不适用于GCC/G ++ 4.3.4 20090804.根据C++标准,哪种行为是正确的?

template <int N>
struct A : A<N-1> {};

template <>
struct A<0> {};

struct B : A<1> {};

template <int N>
void Func(const A<N> &a) {}

int main()
{
    A<1> a;   //is derived from A<0>
    Func(a);  //vs2008: ok, g++: ok
              //Comeau: ok

    B b;      //is derived from A<1>
    Func(b);  //vs2008: ok, g++: error, no matching function for call to Func(B&)
              //Comeau: error: no instance of function template "Func" matches the
              //        argument list. The …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance gcc templates visual-studio-2008

13
推荐指数
1
解决办法
415
查看次数

标签 统计

c++ ×1

gcc ×1

inheritance ×1

templates ×1

visual-studio-2008 ×1