This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

undefined reference


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
=================================================================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]