全局模板函数的问题
由于某种原因,我似乎无法在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'
}
};
我应该做什么?
For some reason I can't seem to call my global template function in GCC...
Global function defined in "globals.h":
template <typename T1, typename T2> inline T1 Min (const T1 & v1, const T2 & v2)
{
return v1 < v2 ? v1 : v2;
}
Call to function from class defined in "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'
}
};
What should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
g++ 版本 4.3.4 可以正确编译它们,仅在最后一行给出错误。请参阅 http://ideone.com/cD13Y。您使用什么版本?
g++ version 4.3.4 compiles these correctly, giving an error only for the last line. See http://ideone.com/cD13Y. What version are you using?