Hi all,
I'm having problems with declaring a template friend function. It seems like
I've done everything as explained
in C++ FAQ, but still, I'm getting the linker error (unresolved external
'aFunc(A<char> const&)' ) in
the following sample program. Tried it on GCC and Borland's compiler.
Can somebody please show me the correct way to fix this?
Thanks,
Dmitry
// all the following code is located in a single source file
#include <iostream>
template<typename T> class A; // forward class declaration
template<typename T> void aFunc(const A<T>&);
template <typename T>
class A
{
public:
A(T _object): value(1), object(_object) {}
T& GetObject() { return object; }
friend void aFunc(const A<T>&);
private:
T object;
int value;
};
// friend function
template <typename T>
void aFunc(const A<T>& container)
{
std::cout << "value: " << container.value;
}
int main()
{
A<char> myClass('a');
aFunc(myClass);
return 0;
}