Topic: How to construct class member - template object using non-default constructor ?


Author: Zijian Huang <Zijian.Huang@ncl.ac.uk>
Date: 27 Dec 1994 01:04:15 GMT
Raw View
In article <NEWTNews.10770.786299039.bob@koba.elementrix.co.il>, bob@elementrix.co.il says:
>

>Please e-mail me.
>Thanks, beforehand.
>Bob.
>
Answer:
  I am not sure what is the meaning--'put them all in the same header file...'
Usually, in C++, you should put or include the implementation code for
the template class into the 'same' header file. That is the way you should
do in BC, though some C++ compiler can handle something like 'temp.h' and
'temp.c' and then produce 'temp.o'.

Zijian Huang
Computing Science Dept
University of Newcastle upon Tyne
Zijian.Huang@ncl.ac.uk




Author: bob@elementrix.co.il
Date: Thu, 01 Dec 94 08:10:31 PDT
Raw View

Hello, All !!!

I have template class with only one constructor, which has parameters
(non-default constructor). I want some object of this class to be a member of
another class, but not a pointer. Here is an example:

template <class T>
class A
{
public:

  A (int param);
  ...
  int func (void);

};


class B
{

  A<int> a(5);  // this doesn't work. What can I do to make it work, without
                // changing it to pointer
  ...

Can anyone tell me, why BCW 4.0 Linker doesn't find all non-inline functions of
class A. I put them all in the same header file as required by "Smart
Templates" option of BCW 4.0, but I get linker error: "Undfined symbol
A<int>::func (void) in module ...".

Please e-mail me.
Thanks, beforehand.
Bob.