Re: problem with template specialisation
* Xavier Serrand:
The following code don't raise even a warning with DevC++ but with VC6 :
Compiler Error C2908 : explicit specialization; 'template' has already been
specialized from the primary template
with the following code
template <typename T> struct Elem_
{
long x; /* coordonn?e x de l'?l?ment */
long y; /* coordonn?e y de l'?l?ment */
T el; /* ?l?ment d'indice <x,y> */
/* R?solution des collisions */
struct Elem_ * next_x; /* r?sol. pour des x de m?me indice selon h1 */
struct Elem_ * next_y; /* r?sol. pour des y de m?me indice selon h2 */
};
template <typename T> struct TableDisp_
{
struct Elem_<T> ** table; //Compiler Error C2908 with VC6 only (not with
DevC++ )
long nbEntrees;
};
template <typename T> class MatrixCRS
{
typedef struct Elem_<T> Element; //Compiler Error C2908 with VC6 only (not
with DevC++ )
public:
MatrixCRS() {};
MatrixCRS(T defaultValue);
~MatrixCRS();
T getDefaultElt();
private:
T m_default;
};
At a glance I see nothing wrong with the template stuff.
And VC6 should just be ditched, if you have that option.
However, general comments:
* it's not a good idea to reinvent std::vector (your class TableDisp_);
just use std::vector instead.
* Class TableDisp_ lacks a copy constructor, and it needs one; just use
std::vector instead.
* On naming issues, "get" adds no value and detracts from readability in
C++ (consider, readability of getSin(1)*getSin(2) or
computeSin(1)*computeSin(2) instead of just sin(1)*sin(2)), and,
arbitrary short forms such as "Elt" are just a way to add more work
when mispelinsg have to be corrected later on.
I can fix the problem putting all declarations in the class ... but i would
like to find a way to have structs declarations outside the class
MatrixCRS... is it possible ? is it a good idea?
There were workarounds for most things wrong with VC6, but unless you
absolutely have to support that compiler it's not a good idea to do that.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?