This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
undefined reference
- To: egcs at cygnus dot com
- Subject: undefined reference
- From: Xiaomao Xiao <xiao at cmold dot com>
- Date: Sun, 19 Jul 1998 13:50:30 -0400 (EDT)
- Reply-To: xiao at cmold dot com
Hi there:
I asked the sample question before. But I'm afraid that I didn't state the
problem clearly. I include the code which produced the 'undefined reference'
problem on my Linux box.
=============================================================================
The program is as follows:
#include <iostream>
#include <iomanip>
template <class T>
class MyTest
{
private:
T data_;
public:
MyTest(T data = 0)
{
data_ = data;
}
friend ostream & operator <<(ostream & out, const MyTest<T> & test);
};
template <class T>
ostream & operator <<(ostream & out, const MyTest<T> & test)
{
out << setw(12);
out << test.data_ << endl;
return (out);
}
template class MyTest<float>;
template ostream & operator <<(ostream &, const MyTest<float> &);
main()
{
MyTest<float> test;
cout << test;
}
=============================================================================
The error message is:
/tmp/cca005831.o: In function `operator<<(ostream &, MyTest<float> const &)':
/tmp/cca005831.o(.text+0x61): undefined reference to `operator<<(ostream &, smanip<int> const &)'
=============================================================================
The compile command is:
gcc -fguiding-decls -fno-implicit-templates junk.cpp -L/usr/local/lib -lstdc++ -o junk
Could anybody tell me what I should do to make this piece of code work? Thanks
in advance.
--
Xiaomao
=================================================================
Xiaomao (Mark) Xiao E-Mail: xiao@cmold.com
C-MOLD TEL: (607) 257-4949 x 699
31 Dutch Mill Road FAX: (607) 257-6355
Ithaca, NY 14850 URL: http://www.cmold.com
=================================================================