我想从模板函数调用模板成员函数。这段代码是在在线编译器(http://coliru.stacked-crooked.com/a/5ff8acce3ceeb205)中编译的,但是当我们尝试使用visual studio 2015编译相同的代码时,我们得到 错误C2228:'。doSomething'的左边必须有class / struct /联合 即可。我需要帮助来修复此错误。任何帮助将不胜感激。
#include <iostream>
class A {
public:
template<class S>
int doSomething( S &s ) {
//Do something, for example just print
std::cout<< s <<std::endl;
return 0;
}
};
template<class S, class T>
int foo( S &s, T &v ) { return v.doSomething(s); }
int main(){
A a;
int x = 5;
foo(x,a);
return 0;
}