473,387 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

[Q] Template: Undefined Constructors

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?
Jul 22 '05 #1
3 1174
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
rg********@pobox.com
Remove the 'g' from my address to send me mail.
Jul 22 '05 #2
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
Jul 22 '05 #3
eg******@verizon.net (Eric) wrote in message news:<1gci5k9.17r0locvblnj0N%eg******@verizon.net> ...
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
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: K.S. | last post by:
If have template lets call it template class MyTemplate<class T> and the files MyTemplate.cc & MyTemplate.hh In /* MyTemplate.cc */ // definitions .... template class MyTemplate<someType>;...
3
by: jack | last post by:
Hi there, I have a function F(x, y, z) and I want to calculate f(a) + f(b), where f(x) = F(x, x, z0) z0 is fixed. Suppose somebody wrote a routine called "Compute" which simply computes f(a)...
3
by: W. Cerven | last post by:
I am using the C++ STL container "list" to create a template nested list. Attached are my basic code and compiler errors. Oddly enough, I when I create a non-template version of this nested list,...
13
by: MurphyII | last post by:
Just a little sample : class A { public: A( ) { } template<typename T> A( const typename T& a) {
5
by: truce | last post by:
I searched but couldn't find anything _quite_ like this. I have some code I inherited that needs some work. Basically I have a template that is instantiated in the c++ code and so only the...
0
by: Dijkstra | last post by:
Hi! I am writing a program in which I need to keep track of how many objects of a given class exists at a time. The task is to do it using templates. The objects to be counted are of the class Note:...
1
by: petschy | last post by:
hello, i've run into an error when qualifying a copy ctor 'explicit'. the strange thing is that i get a compiler error only if the class is a template and declare the variable as X<Zx = y....
1
by: Ioannis Gyftos | last post by:
Hello, First the code :) /////////////////////////////////////////////////////////////////////////////////// // in another header file namespace LJC{
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.