a compiation issue with gcc

Peter Doerfler doerfler@techinfo.rwth-aachen.de
Thu May 19 12:36:00 GMT 2005


Hi Damanjit.

As far as I understand there is some confusion with pointers to member 
functions esp. if they are static depending on the compiler.

I managed to get your code compiled by removing the & in 
>         typedef B<T,&ASFreeWrapper> Type;
Can't recall which is correct but I think the version without &.

and of course including malloc.h for free().

This is with gcc4.0.1 on a x86 system.
On my gentoo version of gcc3.4.3 I get an ICE, but I guess that is a known 
issue. Does anybody know?

If you are interested: I found 
http://www.codeproject.com/cpp/FastDelegate.asp
an informative read. Goes into detail what the standard says about member 
function pointers and what different compilers actually implement.

Hope this helps
- Peter

On Thursday 19 May 2005 14:12, Damanjit Singh wrote:
> #include "iostream.h"
> #include "stdio.h"
> template <class T,void (*DestroyCallback)( T )> class B
> {
> private:        
>         int a;
> };              
> template <class T> class A
> {
> private:
>         static void ASFreeWrapper( T Ptr )
>         {
>                 free( Ptr );    
>         }
> public:
>         typedef B<T,&ASFreeWrapper> Type;
>
> };
> int main()
> {
>         A<int *> a;
>         return 0;
> }

On Thursday 19 May 2005 14:12, Damanjit Singh wrote:
> The following code  does not compile with gcc (ggc -c simple.cpp) and
> gives the following errors ( where as the code compiles in windows
> VC++ )-
> Could someone tell me the reason for this, and if there is an
> available workaround.
> Thanks,
>
> #include "iostream.h"
> #include "stdio.h"
> template <class T,void (*DestroyCallback)( T )> class B
> {
> private:
> 	int a;
> };
> template <class T> class A
> {
> private:
> 	static void ASFreeWrapper( T Ptr )
> 	{
> 		free( Ptr );
> 	}
> public:
> 	typedef B<T,&ASFreeWrapper> Type;
>
> };
> int main()
> {
> 	A<int *> a;
> 	return 0;
> }
>
> /* Here is the error reported by gcc -
> simple.cpp:9: warning: all member functions in class `A<T>' are private
> simple.cpp: In instantiation of `A<int*>':
> simple.cpp:21:   instantiated from here
> simple.cpp:16: invalid use of undefined type `class A<int*>'
> simple.cpp:9: declaration of `class A<int*>'
> */



More information about the Gcc-help mailing list