* DEC C++ template trouble.
@ 1996-03-13 5:00 Bob MacCallum
1996-03-14 5:00 ` Bob MacCallum
0 siblings, 1 reply; 2+ messages in thread
From: Bob MacCallum @ 1996-03-13 5:00 UTC (permalink / raw)
I'm not a regular reader of this group I'm afraid, but sadly there are no
C++ people in my group. I hope someone can help.
The basic problem is with the instantiation and/or linkage of class
template member functions in separate *.C files (i.e. not inlined in the .H
file).
I thought the Online Documentation would help, but I can't even get the
simplest case to work (as it does with the SGI DCC compiler). I'm sorry I
don't have the version number, but cxx -V gives a whole load of numbers,
many of them being 4.2.x.x If version 5.0 doesn't have this problem, it
will be hard to obtain (one DEC and 20 SGIs, busy sysadmin).
Here goes
//// file entity.H
template <class T>
class entity
{
T item;
public:
entity(const T& newT) : item(newT)
{
}
virtual void doSomething();
};
//// file entity.C
#include "entity.H"
template <class T> void entity<T>::doSomething()
{
cerr << item << '\n';
}
//// file test.C
#include <iostream.h>
#include "entity.H"
main()
{
entity<int> fred(12345);
fred.doSomething();
return 0;
}
//// compilation goes as follows
bsmax01<325>% cxx test.C entity.C |& demangle
test2.C:
entity.C:
ld:
Error: Undefined:
__vtbl_10entity__Ti Make sure that the first member function of 'entity<int>' is defined.
entity<int>::doSomething(void)
bsmax01<326>%
I've tried combinations of #pragma define_template entity<int> and the
command-line option, but the only thing which makes this work is to have
the body code for entity<T>::doSomething in the header file.
I would be very happy if someone can point out my obvious errors,
thanks in advance,
Bob.
--
++++++++++++++++++++++++++++++ Bob MacCallum ++++++++++++++++++++++++++++++
+++++++++++++++ Biomolecular Structure and Modelling Group ++++++++++++++++
++++++++++++ Department of Biochemistry and Molecular Biology +++++++++++++
++++++++++++++++ University College London, WC1E 6BT, UK ++++++++++++++++++
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: DEC C++ template trouble.
1996-03-13 5:00 DEC C++ template trouble Bob MacCallum
@ 1996-03-14 5:00 ` Bob MacCallum
0 siblings, 0 replies; 2+ messages in thread
From: Bob MacCallum @ 1996-03-14 5:00 UTC (permalink / raw)
Hold on, with a clear head this morning, I managed to get it to work.
At the end of entity.C, I add the line
#pragma define_template entity<int>
and it works. I was assuming that it would be ok in test.C.
But it wasn't. I'll read the docs again and figure out a way for this to
be a bit more flexible. I don't want to edit these files each
time I use them differently in a client program...
Sorry to waste people's time,
Bob.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-03-14 5:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-03-13 5:00 DEC C++ template trouble Bob MacCallum
1996-03-14 5:00 ` Bob MacCallum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox