Why does compile error C2951 occur in a template statement but not in a template method?

My example code is below

#include <iostream>
using namespace std;
#define NUM 1

class A
{
public:
    template <int N>
    int operator()() { return N; }

    template <int N>
    int f() { return this->operator()<N>(); }
};

template <class TC>
int foo(TC& tc)
{
    int a = tc.template f < NUM > ();        // OK.
    a += tc.template operator() < NUM > ();  // Error C2951 on VisualStudio 2013
    return a;
}

int main(void)
{
    A a;
    cout << foo(a) << endl;
    return 0;
}

      

I know that the compilation error can be avoided by replacing a += tc.template operator() < NUM >()

with a += tc.operator()<NUM>()

, but this substitution cannot be transplanted into LLVM for Mac OS X.

To my embarrassment, this A::operator()

and A::f

are functions of the member, why one compiles OK, so one could not?

+3


source to share





All Articles