[Q] Template: Undefined Constructors

E

Eric

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 )
{
}
};
 
C

Claudio Jolowicz

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?
 
M

Michiel Salters

Ok, this is very strange.

in TRegionGrower.h, I've got:

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

TRegionGrower( void );
~TRegionGrower( void );
};
[ 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top