Original Post
Hi,
I have a problem with a simple class template for which I like to implement the stream operators. Here is the code:
RasterLayer.h
template<typename T>
class RasterLayer
{
public:
// Streams
friend std::ostream& operator<<( std::ostream& os, const RasterLayer<T>& src );
private:
// Data members
unsigned int m_Width, m_Height;
std::vector<T> m_Data;
};
RasterLayer.inl
// Stream construction
template<typename T>
RasterLayer<T>::RasterLayer( std::ifstream& is )
{
// Read header
std::string dummy;
is >> dummy >> m_Width;
is >> dummy >> m_Height;
is >> dummy >> dummy;
is >> dummy >> dummy;
is >> dummy >> dummy;
is >> dummy >> dummy;
// Allocate required memory
unsigned int nbElements = m_Width * m_Height;
m_Data.resize( nbElements );
// Read data
for ( unsigned int i = 0; i < nbElements; ++i )
{
is >> m_Data[i];
}
}
RasterLayer.inl is included at the end of RasterLayer.h.
When I try now to write something like this:
RasterLayer<int> aLayer; // This should create an instance of << ? std::cout << aLayer;The linker tells me that he can't resolve the << operator? Any help is greatly appreciated! -Dirk BTW: I looked into the C++ Primer by Lippman and this is the way he suggest how to implement this! [Edit: Use the [source], Luke.] [edited by - Oluseyi on May 11, 2004 11:18:22 AM]