开发者

Problem with global template function

开发者 https://www.devze.com 2023-03-03 06:08 出处:网络
For some reason I can\'t seem to call my global template function in GCC... Global function defined in \"globals.h\":

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); /开发者_StackOverflow/error: 'class Test' has no member named 'Min'
    }
};

What should I do?


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消