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
`GeneralPolygons::readObjFile(std::basic_string<ch ar,
std::char_traits<char>, std::allocator<char)':
core/generalpolygons.cpp:222: undefined reference to
`std::basic_ostream<char, std::char_traits<char& operator<<
<float>(std::basic_ostream<char, std::char_traits<char&,
Point<floatconst&)'
Here is the code:
In point.hpp
// foward declaration needed for the template friend functions
template<typename Tclass Point;
// forward declarion of the Point's friend function
template<typename Tstd::ostream & operator<<( std::ostream &os,
const Point<T&p );
template<typename T>
class Point
{
public:
...
friend std::ostream & operator<< <T>( std::ostream &os, const
Point<T&p );
};
in point.cpp
template<typename 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