Can anybody please help me make this work?
Donor-enumerate() doesn’t work, gcc gives no matching function error.
template < class T >
struct mesh;
template < class T >
struct meshBone
{
friend struct mesh< T >;
private:
T *_obj;
};
template < class T >
struct mesh
{
template < class U >
void enumerate( U& rcv )
{
}
void connect( T* obj, mesh< T >* donor )
{
class object_replacement
{
T* _obj;
public:
object_replacement ( T* t ): _obj(t) {}
bool operator()( meshBone<T> * bone )
{
bone->_obj = _obj;
return true;
}
} obj_rpl(obj);
donor->enumerate (obj_rpl);
}
};
In C++03 you cannot use a local type as a template type argument.
object_replacementis a local type (it is local tomesh<T>::connect(T*, mesh*)) and you try to use it as the template argumentUofmesh<T>::enumerate<U>. gcc gives this rather unhelpful error message that there is “no matching function.”The “no local types” rule has been removed in C++0x, so if you have a sufficiently recent version of gcc you can compile using
-std=c++0xand this should work fine (I’ve verified this with gcc 4.5.1). If that isn’t an option, you just need to makeobject_replacementnot a local type, i.e., extract it and make it a nested type of themesh<T>class template: