Hi guys, I think from what I found on the net that the code is correct
and there's no problem when I compile the files. The problems occurs
when I link them. I have a friend function which outputs points data to
the ostream. Here is the error message:
objs/generalpolygons .o(.text+0xf08) : In function
`GeneralPolygon s::readObjFile( std::basic_stri ng<char,
std::char_trait s<char>, std::allocator< char)':
core/generalpolygons .cpp:222: undefined reference to
`std::basic_ost ream<char, std::char_trait s<char& operator<<
<float>(std::ba sic_ostream<cha r, std::char_trait s<char&,
Point<floatcons t&)'
Here is the code:
In point.hpp
// foward declaration needed for the template friend functions
template<typena me Tclass Point;
// forward declarion of the Point's friend function
template<typena me Tstd::ostream & operator<<( std::ostream &os,
const Point<T&p );
template<typena me T>
class Point
{
public:
...
friend std::ostream & operator<< <T>( std::ostream &os, const
Point<T&p );
};
in point.cpp
template<typena me T>
std::ostream & operator<<(std: :ostream &os, const Point<T&p )
{
os << p.x << " " << p.y << " " << p.z;
return os;
}
how I use it in the code
std::cout << Point<float>( 0.0 ) << std::endl;
Thanks for your help, Mark