How to call a class member function from a fuction template?

Viewed 88

I want to call a template member function from a template function. This code is getting compiled in online compiler(http://coliru.stacked-crooked.com/a/5ff8acce3ceeb205) but when we try to compile the same code using visual studio 2015 we get error C2228: left of '.doSomething' must have class/struct/union. I need help to fix this error. Any help would be appreciated.

#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;
}
0 Answers
Related