gi*******@mariani.ws (Gianni Mariani) wrote in message news:<48**************************@posting.google. com>...
The code below compiles on gcc 3.4.0 and Comeau's 4.3.3 but MSVC++ 7.1
dies complaining about somthing <unknown>.
Is this valid ?
I believe that VC 2003 thinks that on that line, T is a type - not a
template parameter. I realize this doesn't help you much ...
Maybe my reasoning is bad, but I determined this after swapping x for
T --
friend void T::X( T2 t ); --> friend void x::X( T2 t );
-------------------------------------------------------
The following code builds fine with that little change:
--------------------------------------------------------
#include "stdafx.h"
struct x
{
template <typename T>
static void X( T t )
{
delete t;
}
};
template <typename T=x>
class Foo
{
template <typename T2>
friend void x::X( T2 t );
~Foo(){}
public:
void FinishMe()
{
T::X( this );
}
};
int _tmain(int argc, char** argv)
{
Foo<> * zz = new Foo<>;
zz->FinishMe();
}
-----------------------------------------------------------------------------
**** in fact, this simpler example breaks VC 2003 with the same error
and the same use of 'T' ****
-----------------------------------------------------------------------------
#include "stdafx.h"
struct x
{
static void X() { }
};
template <typename T>
class Foo
{
friend void T::X(); // <-- error C2063: '<Unknown>' : not a
function
};
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
------------------------------------------------------------------------------
* Using typedef's, one can work around the simpler problem I've
described - but that gets away from templates ... not sure what your
constraints are or if something like
template<class T> class Foo;
typedef void (*XTC)(Foo<x>*);
XTC xtc = x::X<Foo<x>* >;*
...
is even reasonable for you. I'm sure someone else may have a better
idea.
------------------------------------------------------------------------------
#include "stdafx.h"
struct x
{
static void X() { }
};
typedef void (*TX)();
TX tx = x::X;
template <typename T>
class Foo
{
friend void (tx)();
};
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
----------
Hth,
-Luther