Suppose I'm writing a template function foo that has type parameter T. It gets an object of type T that must have method bar(). And inside foo I want to create a vector of objects of type returned by bar.
In GNU C++ I can write something like that:
template<typename T>
void foo(T x) {
std::vector<__typeof(x.bar())> v;
v.push_back(x.bar());
v.push_back(x.bar());
v.push_back(x.bar());
std::cout << v.size() << std::endl;
}
How to do the same thing in Microsoft Visual C++? Is there some way to write this code that works in both GNU C++ and Visual C++?