This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How do I manually instantiate template functions with -fno-implicit-templates
- To: markj at ibmoto dot com (Mark Johnstone)
- Subject: Re: How do I manually instantiate template functions with -fno-implicit-templates
- From: Mark Mitchell <mmitchell at usa dot net>
- Date: Wed, 7 Jan 1998 09:41:50 GMT
- Cc: oliva at dcc dot unicamp dot br, egcs at cygnus dot com
- References: <orafd9z7c1.fsf@sunsite.dcc.unicamp.br><199801062147.PAA42372@pita.ibmoto.com>
- Reply-To: mmitchell at usa dot net
Here is a test case for what I need:
test.h:
#include<iostream.h>
struct test_box
{
void print(void) {cout << "this is a test" << endl;}
};
void test(test_box *); // Just a forward declaration
It is this line that is the problem. You should have written:
template <class BOX> void test(BOX* the_box);
here. A long explanation below.
test.C:
#include "test.h"
template <class BOX> void test(BOX *the_box)
{
the_box->print();
};
template void test<> (test_box *); // This is the guiding decl
main.C:
#include "test.h"
main()
{
test_box box1;
test(&box1);
}
First, the use of -fno-implicit-templates makes no difference in this
particular case, so let's not worry about it. If we look at (some of)
the symbols in each .o:
supernova% nm test.o | test-c++filt
00000000 T void test<test_box>(test_box *)
supernova% nm main.o | test-c++filt
U test(test_box *)
We can see what's happenning. The main.C file is trying to call a
non-template function; the test.C file defines (and causes the
instantiation of) a template function. They don't match, according to
the Standard. That's why the prototype should be a template
prototype, not a non-template prototype.
--
Mark Mitchell mmitchell@usa.net
Stanford University http://www.stanford.edu