473,322 Members | 1,417 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,322 software developers and data experts.

Template class member for one specialisation only?

Ben
Hi all.

I'm trying to make a third party lib (Rogue Wave's math.h++) compile
(under VC7) and I'm having some problems with what I think is code
that was written specifically to work with the older (less standard)
versions of the VC compiler.

There's a class like this (the comments are mine):

class RWMathVec
{
// .. constructors + other stuff.

// the interesting bit.
RWMathVec( const RWMathVec<double>& re, const RWMathVec<double>& i
);
};

Now that last c'tor is not implemented anywhere except a .cpp file
(one that isn't #include'd anywhere) in the library and in there it is
specialised (am I applying this term correctly here?) for a type
DComplex, like this:

template<>
RWMathVec<DComplex>::RWMathVec( const RWMathVec<double>& re, const
RWMathVec<double>& im )
{
//.. stuff.
}

Now, I don't really think this is right (up to standard?) because
there is no definition for the c'tor in the class definition, and sure
enough I get warnings when trying to compile the library:

C:\vs.net\Vc7\include\xmemory(111) : warning C4661:
'RWMathVec<T>::RWMathVec(const RWMathVec<double> &,const
RWMathVec<double> &)' : no suitable definition provided for explicit
template instantiation request

This is what I would expect. So, I have a few questions:

1. Is it legal/good practice to declare a c'tor (or any member) in a
template class and then provide only certain specialised
implementations of that c'tor?
2. What can I do to sort this problem out?

I want to fix it without having to delve too deep or make too many
changes to the code. I'm hoping that compile and link errors can help
me to judge whether the code it 'right' or not after making my
changes. I suppose I'm looking for the 'right' way to do this sort of
thing!

I should just say that when I tried taking the specialised c'tor
implementation code out of the .cpp file and sticking it inline in the
class def and changing it to work on any type T, rather than just on
DComplex I got compile errors. This was because the implementation has
code like this in:

blah = DComplex(re(i),im(i));

and when I changed that to:

blah = T(re(i),im(i));

I got:

.../../rw\math\mathvec.cc(147) : error C2564: 'int' : a function-style
conversion to a built-in type can only take one argument
which I understand. So that tells me why they have specialised this
c'tor.

Hope that all makes sense and I wasn't too long-winded.

Ben
Jul 19 '05 #1
1 4799
"Ben" <be****@hotmail.com> wrote...
I'm trying to make a third party lib (Rogue Wave's math.h++) compile
(under VC7) and I'm having some problems with what I think is code
that was written specifically to work with the older (less standard)
versions of the VC compiler.
[...]


You might be better off talking to Rouge Wave or posting your
question to a VC++ newsgroup. Math.h++ is reported obsolete
by Rogue Wave itself. Whether you will be able to upgrade your
library is not really a language question. However, from the
sanity point of view, if the manufacturer of the product has
given up on it, there is no sense to spend time doing their job
just to save a few bucks.

Of course, you could continue rewriting Math.h++ to work with
the current version of VC++, but (a) wouldn't you rather solve
your own problems? and (b) what if you need to change compilers,
will you rewrite all your other libraries that need that, too?

As to the specialisation, try declaring it in the header. Let
the implementation be in the translation module, just add

template<>
RWMathVec<DComplex>::RWMathVec(
const RWMathVec<double>& re,
const RWMathVec<double>& im);

after the RWMathVec template definition.

If that doesn't solve the problem, try asking in a VC++ newsgroup.

Victor
Jul 19 '05 #2

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

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
2
by: Simon G Best | last post by:
Hello! I have a query regarding explicit specialisation of class templates which are themselves members of class templates. Here's what I want to do: template< class T > struct pink { ...
7
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
1
by: pauljwilliams | last post by:
Consider the following scenario: A template class Diag is defined for a generic class T, with a single member function, State(), returning a boolean, defined as returning false. For some...
8
by: Paul Roberts | last post by:
Hi, I'm hoping somebody here can help me with a simple problem of template syntax. Here's an example: template<typename T, int iclass A { static int a;
2
by: David O | last post by:
I am using the CRTP (Curiously Recurring Template Pattern) to provide a set of low-level functions customizable by environment. Using CRTP ensures that all the function have the same signatures,...
1
by: Martin | last post by:
I'm trying to make a partial specialization of a class of mine. Can someone please tell me what's wrong with the following code? GCC gives me the error "invalid use of undefined type "class X<int,...
8
by: Rahul | last post by:
Hi, Is there a way to partially specialize only a member function of a template class (not the whole class). e.g. template <typename A, typename B> class Base { public:
9
by: stephen.diverdi | last post by:
Can anyone lend a hand on getting this particular template specialization working? I've been trying to compile with g++ 4.1 and VS 2005. ...
3
by: Christof Warlich | last post by:
Hi, I just need a specialization for only one member function of a template class with _many_ members. Do I really have to duplicate the source code for all the members, i.e. for those that do...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.