Why this template code fails to comple?

"Chen (陈) Jun (军)" chjfth@gmail.com
Mon Dec 15 03:05:00 GMT 2008


Please help me check the small C++ snippet.

class Imy
{
public:
    enum ReCode_et {
        E_Success = 0,
        E_Fail = -1,
    };
};

template<class T>
bool CheckSuccess(typename T::ReCode_et err)
{
    if(err==T::E_Success)
        return true;
    else
        return false;
}

int main()
{
    return !CheckSuccess(Imy::E_Success);
}

When compiling with gcc 4.1.0, it fails with


tpl1.cpp: In function ‘int main()’:
tpl1.cpp:21: error: no matching function for call to 
‘CheckSuccess(Imy::ReCode_et)’


But I think the CheckSuccess can decude that T is Imy , right?



More information about the Gcc-help mailing list