R
rf
As I understand it, it is legal to have a template member function of a
non-template class, as in the following example:
class XYZ
{
public:
template <class T> void fn(T* ptr)
{
T val = *ptr;
cout << val << endl;
}
};
This example compiles and works as expected. However, if I move the
member function definition out of the class definition as follows:
(xyz.h)
#ifndef _XYZ_H_
#define _XYZ_H_
class XYZ
{
public:
template <class T> void fn(T* ptr);
};
#endif /* _XYZ_H_ */
(xyz.cpp)
#include "xyz.h"
template <class T> void XYZ::fn(T* ptr)
{
T val = *ptr;
cout << val << endl;
}
Then MS Visual C++ 5.0 gives me the error "error C2660: 'fn' : function
does not take 1 parameters" on the line I invoke the function from as
shown below:
int ix = 43;
XYZ xyz;
xyz.fn(&ix);
Is this a compiler bug, or have I overlooked something?
Thanks,
BF
non-template class, as in the following example:
class XYZ
{
public:
template <class T> void fn(T* ptr)
{
T val = *ptr;
cout << val << endl;
}
};
This example compiles and works as expected. However, if I move the
member function definition out of the class definition as follows:
(xyz.h)
#ifndef _XYZ_H_
#define _XYZ_H_
class XYZ
{
public:
template <class T> void fn(T* ptr);
};
#endif /* _XYZ_H_ */
(xyz.cpp)
#include "xyz.h"
template <class T> void XYZ::fn(T* ptr)
{
T val = *ptr;
cout << val << endl;
}
Then MS Visual C++ 5.0 gives me the error "error C2660: 'fn' : function
does not take 1 parameters" on the line I invoke the function from as
shown below:
int ix = 43;
XYZ xyz;
xyz.fn(&ix);
Is this a compiler bug, or have I overlooked something?
Thanks,
BF