2011-05-04 74 views
0

出于某种原因,我似乎无法在打电话给我全局模板功能 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' 
    } 
}; 

我该怎么办?

+0

你是否在'globals.h'中包含'Test.h'? – Naveen 2011-05-04 07:39:14

+0

不,我为什么要那样做? – Ryan 2011-05-04 07:40:18

+0

只是怀疑一个圆形的包容。否则,代码应该很好地编译(除了最后一个语句'int f = ...')。 – Naveen 2011-05-04 07:43:29

回答

1

g ++ 4.3.4版本正确编译它们,只给出最后一行的错误。见http://ideone.com/cD13Y。你使用什么版本?

+0

嗯......我使用苹果GCC 4.2.1 – Ryan 2011-05-04 07:50:25

+0

其实,这个问题真的与包括......感谢,纳文! – Ryan 2011-05-04 09:27:00