This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
template with friend function problem
- To: gcc at gcc dot gnu dot org
- Subject: template with friend function problem
- From: Vladimir Yelistratov <yelistratov at gmd dot de>
- Date: Mon, 20 Mar 2000 15:41:53 +0100
- Organization: GMD
Dear colleagues!
I have the following problem with friend function of a
template class on the following configuration:
gcc -v
Reading specs from <...>lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)
I try to do everything as stated in the corresponding section of FAQ
I compile everything WITHOUT special flags
______________________________________________
// Vector.h file
// declare class
template<class Type> class CoolVector;
// declare friend function
template <class Type> CoolVector<Type> cross_3d(const CoolVector<Type>&,
const CoolVector<Type>&);
template<class Type> class CoolVector : public CoolBaseVector {
friend CoolVector<Type> cross_3d<>(const CoolVector<Type>&, //
cross-product
const CoolVector<Type>&); // of 3d-vectors
}
_______________________________________________
// Vector.C file
#include <Vector.h>
template<class Type>
CoolVector<Type> cross_3d(const CoolVector<Type>& v1, const
CoolVector<Type>& v2) {
/* implementing function here */
}
________________________________________________
I try to compile these files for dynamic library. I use special file to
instantiate
everything that is necessary:
________________________________________________
// instantiate.cpp file
#include <Vector.C>
/* I instantiate also non-friend functions. It goes well */
template CoolVector<float> cross_3d(const CoolVector<float>&, const
CoolVector<float>&);
_______________________________________________
So, I get my library and try to compile a small program with it.
I get the following error:
<path to library>.so: undefined reference to `cross_3d(CoolVector<float>
const &, CoolVector<float> const &)'
Once more, I do not use special flags for dealing with templates and
instantiation of non-friend functions goes quite well.
What is wrong with my instantiation of friend functions?
Thank you for your help,
Vladimir