#include <iostream>
#include<string>
struct Name
{
std::string name ;
std::string GetString() const
{
std::cout<<"GetString Called"<<std::endl;
return name;
}
};
struct Person
{
};
void SetString(std::string n)
{
std::cout<<"SetString Called"<<std::endl;
}
//this function template will work if the class type has a member function named GetString
template <typename T> auto Function (T const & x) -> decltype( x.GetString(), void())
{ SetString(x.GetString());
};
int main()
{
Name n;
Function(n); //works because Name has member function GetString
Person p;
//Function(p); //wont work because Person has no member function named GetString
return 0;
}