multiple-definition problem with implicit/explicit templatespecializations

D

D.Cakirkaya

I'm having multiply-defined error for a non-static member function
(e.g Check ) of my class template (e.g. Processor) when I specialize
it for the same set of arguments (e.g T, U, V and X, Y, Z) as those
that I use to instantiate my template classes (e.g. TUVProcessor and
XYZProcessor). I sure do understand that this not unexpected ( as I
instantiate my template class ProcessorXYZ, the resulting entity is a
specialization of Processor for arguments X, Y, Z and hence the
'multiple-definition'... )
Is there any fast-syntactic turnaround for this link-error?

(Note: I'm using CC compiler (Sun C++ 5.9 SunOs_sparc))

// in file Processor.h
template <class T, class U, class V>
class Processor
{
public:
bool Check();
};

//fully specialized for args T, U, V
template<> bool
Processor<T, U, V>::Check()
{
return true;
}

//fully specialized for args X, Y, Z
template<> bool
Processor<X, Y, Z>::Check()
{
return true;
}

//In file Component.cpp
//The instantiation of the template classes for the same set of
arguments


typedef Processor<T, U, V> TUVProcessor;
typedef Processor<X, Y, Z> XYZProcessor;

TUVProcessor* p1 = new TUVProcessor;
XYZProcessor* p2 = new XYZProcessor;


// file ComponentDeployer includes Component.h (and registers the
component)
//Error message goes like " Multiply-defined in Component.o and
ComponentDeployer.o "...
 
D

D.Cakirkaya

(Do i need to mention that my Processor classes share, and benefit
from, a generic implementation of a multiplicity of methods except for
the Check function.. :))
 
D

D.Cakirkaya

Your options are:

1) Define your specializations as inline functions.

2) Declare, but not define, your specializations in the header file, then
define them in a separate translation unit.

application_pgp-signature_part
< 1KViewDownload

Inlining does help ! Thank you:)
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top