salvador p salvador p - 1 year ago 69
C++ Question

In what situations does new return the same address twice?

Why does the following not compile? It says "error: expected primary-expression before ‘>’ token".

template<typename K, typename V>
struct cmpf {
const K& r;
V& visitor;

cmpf(const K& _r, V& _visitor) : r(_r), visitor(_visitor) {}

template<typename T>
void operator()(T& l) {

if (r.type == a_type(T)) {
return l == r.get<T>(); // DOES NOT WORK
} else return false;

Why does the compiler bot understand this? get() is a function defined in type K with a template argument. In this case, I want to use T as the argument, but the compiler does not recognize this. When I use the following instead, it works (but it's not right, since get is a template function):

return l == r.get();

Answer Source


return l == r.template get<T>();

Read this FAQ for more information: What is the ->template, .template and ::template syntax about?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download