Topic: Sun C++ 4.0 question


Author: hlee@cs.yorku.ca (Henry H. Lee)
Date: 1995/04/17
Raw View
Hi everyone:
 I have a question about Sun C++ compiler 4.0 and appreaciate any
help. The following testing program can be compiled and executed in IBM
Cset++ and Borland C++ compiler but not in Sun C++ 4.0.
 The problem is caused by the function template named Void in my
program. But interesting thing is if I use non-template function (see
the one commoned out) then everything is fine.
 Could anyone know what the problem is?

// ******** This is the program ****************
#include <iostream.h>

class C
{
 int i;
public:
 C(int start) {i=start;}

 void func()
 { cout<<"i is "<<i<<endl; }
};

/*  This one works
void Try(void (C::*fp)(),int n)
{
 C* p=new C(n);
 (p->*fp)();
}*/

// This is the line 20
template <class TYPE> void Try(void (TYPE::*f)(), int n)
    ****************
    here's problem !!!
{
 TYPE* p = new TYPE(n);
 (p->*f)();
}

main()
{
 Try(C::func,1);
 Try(C::func,3);

 return 0;
}

// ***** Here is the output ***********

%CC cpp.C
"cpp.C", line 20: Error: TYPE is not a class name as required for a qualifer.
"cpp.C", line 21: Error: The template argument TYPE is not used in a function parameter.
"cpp.C", line 28: Error: Could not find a match for Try(void(C&), int).
"cpp.C", line 29: Error: Could not find a match for Try(void(C&), int).
4 Error(s) detected.
%