全局模板功能问题

时间:2011-05-04 07:34:23

标签: c++ templates gcc

由于某些原因,我似乎无法在 GCC 中调用全局模板函数 ...

globals.h ”中定义的全局函数:

template <typename T1, typename T2> inline T1 Min (const T1 & v1, const T2 & v2)
{
    return v1 < v2 ? v1 : v2;
}

从“ test.h ”中定义的类调用函数:

#include "globals.h"

class Test
{
public:
    Test()
    {
        int a = 2;
        int b = 3;
        int c = Min(a, b); //error: 'Min' was not declared in this scope
        int d = ::Min(a, b); //error: '::Min' has not been declared
        int e = Min<const int, const int>(a, b); //error: expected primary-expression before 'const'
        int f = this->Min(a, b); //error: 'class Test' has no member named 'Min'
    }
};

我该怎么办?

1 个答案:

答案 0 :(得分:1)

g ++版本4.3.4正确编译这些,仅为最后一行提供错误。见http://ideone.com/cD13Y。你用的是哪个版本?