A
Adam Badura
Hi!
I have a class like:
template<int size_integer, int size_fraction>
class number {
template<typename charT, typename traitsT>
explicit number(const charT* textual, int radix = 10);
template<typename charT>
explicit number<charT, std::char_traits<charT> >(const charT* textual,
int radix = 10); // line 25
}; // line 47
My compiler (MS VS .NET 2005) claims on the second declaration.
j:\number\number.hpp(25) : error C2975: 'number_library::number' : invalid
templ
ate argument for 'size_integer', compile-time evaluatable constant
expression ex
pected
j:\number\number.hpp(47) : see declaration of
'number_library::number'
j:\number\number.hpp(47) : see reference to class template
instantiation
'number_library::number<size_integer,size_fraction>' being compiled
So it is clear that the compiler understends it as a class specialization.
How to avoid it? How to specialzie constructor?
Perhabs this is totaly wrong thing I'm tring to do (I do not have much
experinece with templates). What I want to achive is to have a constructor
which
a) can construct number form textual representation (obviously)
b) do not have to write to versions (for char and wchar_t)
c) allow users to use their types and traits
d) allow simple constructions like
number<10, 10> big = "1000000000000000000000000000000";
But this does not work if I have only one constructor parametrized with
char type and traits type becauce traits type cannot be deducted by the
compiler. My compiler (or the language itself?) does not allow me to have
default parameters here in function. And I don't want to write two versions:
for default traits and parmetrized.
What and how (and why) to do?
Thanks in advance.
Adam Badura
P.S. It is not my homework. I do it for fun and exercise.
I have a class like:
template<int size_integer, int size_fraction>
class number {
template<typename charT, typename traitsT>
explicit number(const charT* textual, int radix = 10);
template<typename charT>
explicit number<charT, std::char_traits<charT> >(const charT* textual,
int radix = 10); // line 25
}; // line 47
My compiler (MS VS .NET 2005) claims on the second declaration.
j:\number\number.hpp(25) : error C2975: 'number_library::number' : invalid
templ
ate argument for 'size_integer', compile-time evaluatable constant
expression ex
pected
j:\number\number.hpp(47) : see declaration of
'number_library::number'
j:\number\number.hpp(47) : see reference to class template
instantiation
'number_library::number<size_integer,size_fraction>' being compiled
So it is clear that the compiler understends it as a class specialization.
How to avoid it? How to specialzie constructor?
Perhabs this is totaly wrong thing I'm tring to do (I do not have much
experinece with templates). What I want to achive is to have a constructor
which
a) can construct number form textual representation (obviously)
b) do not have to write to versions (for char and wchar_t)
c) allow users to use their types and traits
d) allow simple constructions like
number<10, 10> big = "1000000000000000000000000000000";
But this does not work if I have only one constructor parametrized with
char type and traits type becauce traits type cannot be deducted by the
compiler. My compiler (or the language itself?) does not allow me to have
default parameters here in function. And I don't want to write two versions:
for default traits and parmetrized.
What and how (and why) to do?
Thanks in advance.
Adam Badura
P.S. It is not my homework. I do it for fun and exercise.