Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > [Q] Template: Undefined Constructors

Reply
Thread Tools

[Q] Template: Undefined Constructors

 
 
Eric
Guest
Posts: n/a
 
      04-19-2004
Ok, this is very strange.

in TRegionGrower.h, I've got:

--
template <class T>
class TRegionGrower
{
public:

TRegionGrower( void );
~TRegionGrower( void );
};
--

In TRegionGrower.cp, I've got:

--
#include "TRegionGrower.h"

template <class T>
TRegionGrower<T>::
TRegionGrower( void )
{

}



template <class T>
TRegionGrower<T>::
~TRegionGrower( void )
{

}
--

I use this class by doing:

TRegionGrower<UInt8> regionGrower;

I get two link errors telling me that the constructor and destructor are
undefined.

However, if I remove the constructor and destructors from the .cp file
and change the .h file to:

--
template <class T>
class TRegionGrower
{
public:

TRegionGrower( void )
{
}

~TRegionGrower( void )
{
}
};
--

The link errors go away.

Any idea what might be going on here?


 
Reply With Quote
 
 
 
 
Russell Hanneken
Guest
Posts: n/a
 
      04-19-2004
Eric wrote:
>
> I get two link errors telling me that the constructor and destructor are
> undefined.
>
> However, if I remove the constructor and destructors from the .cp file
> and change the .h file to:
>
> template <class T>
> class TRegionGrower
> {
> public:
>
> TRegionGrower( void )
> {
> }
>
> ~TRegionGrower( void )
> {
> }
> };
>
> The link errors go away.


The FAQ addresses this issue:

http://www.parashift.com/c++-faq-lit...html#faq-34.12

--
Russell Hanneken
http://www.velocityreviews.com/forums/(E-Mail Removed)
Remove the 'g' from my address to send me mail.


 
Reply With Quote
 
 
 
 
Claudio Jolowicz
Guest
Posts: n/a
 
      04-19-2004
On Mon, 19 Apr 2004, Eric wrote:

>Ok, this is very strange.
>
>in TRegionGrower.h, I've got:
>
>--
>template <class T>
>class TRegionGrower
>{
>public:
>
> TRegionGrower( void );
> ~TRegionGrower( void );
>};
>--
>
>In TRegionGrower.cp, I've got:
>
>--
>#include "TRegionGrower.h"
>
>template <class T>
>TRegionGrower<T>::
>TRegionGrower( void )
>{
>
>}
>
>
>
>template <class T>
>TRegionGrower<T>::
>~TRegionGrower( void )
>{
>
>}
>--
>
>I use this class by doing:
>
> TRegionGrower<UInt8> regionGrower;
>
>I get two link errors telling me that the constructor and destructor are
>undefined.
>


1. How about giving us the definition of UInt8? With a sensible typedef,
there shouldn't be any errors. If its a macro, anything is possible.

2. Is the last line of code in a separate source file or in
TRegionGrower.cp?

3. What does the command line to (compile and) link the files look like?


>However, if I remove the constructor and destructors from the .cp file
>and change the .h file to:
>
>--
>template <class T>
>class TRegionGrower
>{
>public:
>
> TRegionGrower( void )
> {
> }
>
> ~TRegionGrower( void )
> {
> }
>};
>--
>
>The link errors go away.
>
>Any idea what might be going on here?
>
>
>


--
Claudio Jolowicz


 
Reply With Quote
 
Michiel Salters
Guest
Posts: n/a
 
      04-20-2004
(E-Mail Removed) (Eric) wrote in message news:<1gci5k9.17r0locvblnj0N%(E-Mail Removed)> ...
> Ok, this is very strange.
>
> in TRegionGrower.h, I've got:
>
> --
> template <class T>
> class TRegionGrower
> {
> public:
>
> TRegionGrower( void );
> ~TRegionGrower( void );
> };
> --
>
> In TRegionGrower.cp, I've got:

[ the obvious implementation ]

The FAQ reference in the previous post is correct, although there
currently is an alternative solution. These templates need extra
bookkeeping, as the FAQ explains. This is enabled using the export
keyword on the class, but it is today only supported on the Comeau
compiler.

Regards,
Michiel Salters
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reg constructors/copy constructors inheritance srp113 C++ 3 02-17-2009 04:01 PM
Is the possible to have all the public constructors of the publicbase class as the constructors of a derived class? Peng Yu C++ 5 09-19-2008 10:19 AM
compiler synthesized constructors/copy constructors/assignment operators Jess C++ 5 06-07-2007 11:09 AM
Copy constructors, de/constructors and reference counts Jeremy Smith C++ 2 08-02-2006 11:25 PM
Constructors that call other Constructors Dave Rudolf C++ 12 02-06-2004 03:26 PM



Advertisments