RAD Studio
ContentsIndex
PreviousUpNext
E2472: Cannot declare a member function via instantiation (C++)

If a declaration within a template class acquires a function type through a type dependent on a template-parameter and this results in a declaration that does not use the syntactic form of a function declarator to have function type, the program is ill-formed. For example:

template<class T>
struct A {
static T t;
};
typedef int function();
A<function> a;// error: would declare A<function>::t
// as a static member function

Another example: 

In the example below, the template member 'a' has type 'T'. If the template is instantiated with T as a function type, it implies that 'a' is therefore a member function. This is not allowed and the error message is displayed.

template<T& x> class foo { T a; }
int func(int);
template class foo<func>;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!