Topic: Template function declaration(Copy from comp.lang.c++)
Author: Robin S Tao <ST2599@tntech.edu>
Date: 1999/03/15 Raw View
Hi,
I have a template class, it is defined in file_a.cpp. It is a waste of time
as the lines of codes in file_a.cpp is growing. So I am considering to move
some of the mature functions to file_b.cpp to lower the compiler burden.
Then the problems came.
=============
file_a.cpp
#includes in file_a.cpp
MyTemplate<Class T> MyInstance; // declaration of instance
......
============
file_b.cpp
......
#includes in file_a.cpp
extern MyTemplate<Class T> MyInstance;
......
the compiler gave me that already MyInstance is defined in file_a.obj
If I remove extern MyTemplate<Class T> MyInstance; from file_b.cpp, the
compiler will give 'MyInstance' undeclared identifier. For variables, I
know it is the
correct way to use extern. what is wrong here?
Thanks,
robin
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]