Re: template -> instance -> function unresolved ???

"Ulrich Eckhardt" <eckhardt@xxxxxxxxxxxxxx> schrieb im Newsbeitrag
Mario Semo wrote:
in the following sample i have a template class (wrapping a pointer) and
friend template function accessing private data in the template.
i compile this into a dll (yes i know, there is no exported function from
this dll, but this is just a sample) and
get an unresolved external - the friend function is used, but not

...this declares a function as a friend, but...

template <class Element>
elementForOps (IElemPointer <Element>& ptr)
{ return *(ptr.ivPtr); }

...this is an equally named function _template_, which has not been
a friend, and I think that is also the problem you are having.

i solved the problem now.

template <class Element>
class IElemPointer
typedef IElemPointer<Element> Self;

IElemPointer () : ivPtr(0) {}

#ifdef FIX
template <class Element>
friend Element& elementForOps (Self &);
// friend Element& elementForOps (IElemPointer <Element>&);

Note : there is no difference if i use "Self" (typedefed at the begin of the
class) or the real name (IElemPointer<Element>) !
in both cases the
template <class Element>
before the firiend... fixes the problem.

My suggestion BTW would be to simply overload unary operator* as a member,
but of course that doesn't answer the question why this here doesn't work
and might not match your design.

as i wrote, this is part of a big CollectionClassFramework
(the code was compileable with MSVC++ 6.0 and with some other compilers.
just VC9 runs into troubles. )




C++ FAQ:

Sator Laser GmbH
Geschäftsführer: Michael Wöhrmann, Amtsgericht Hamburg HR B62 932