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

Problem with template class

I have a problem with a template class I have defined:
-----------------------------------------------------------------------------------------------------------------
template <typename T, T min, T max>
class Setting
{
private:
T* value;
public:
Setting() : value(NULL) {}
~Setting() {delete value;}

const T* get() const throw() {return value;}
void set(const T& value) throw(std::exception)
{
if(value < min || value max)
{
throw std::argument_exception("Error");
}

this->value = new T(value);
};
};
-----------------------------------------------------------------------
When I try to define this:
Setting<double, 0.0, 1.0myVal1;

the compiler tells me:
error C2993: 'double' : illegal type for non-type template parameter
'min'
error C2993: 'double' : illegal type for non-type template parameter
'max'

While if I write:
Setting<unsigned int, 1, UINT_MAX, true, truemyVal2;

it works without errors.

Why?

Nov 8 '06 #1
1 4264
al*****************@gmail.com wrote:
I have a problem with a template class I have defined:
-----------------------------------------------------------------------------------------------------------------
template <typename T, T min, T max>
class Setting
{
private:
T* value;
public:
Setting() : value(NULL) {}
~Setting() {delete value;}

const T* get() const throw() {return value;}
void set(const T& value) throw(std::exception)
{
if(value < min || value max)
{
throw std::argument_exception("Error");
}

this->value = new T(value);
};
};
-----------------------------------------------------------------------
When I try to define this:
Setting<double, 0.0, 1.0myVal1;

the compiler tells me:
error C2993: 'double' : illegal type for non-type template parameter
'min'
error C2993: 'double' : illegal type for non-type template parameter
'max'

While if I write:
Setting<unsigned int, 1, UINT_MAX, true, truemyVal2;
Where did those 'true, true' come from?
>
it works without errors.

Why?
Why what? Why is it illegal? Because the Standard says so. Why it
works with 'int'? Because the Standard allows integral types for
non-type template arguments. Why is it that way in the Standard?
Because it is possible to implement with integrals and not possible
with floating-point, IIRC. Try searching "non-type template argument
double" in the archives, you'll find more information.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 8 '06 #2

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

Similar topics

0
by: tyousaf | last post by:
Hi i am new to mysql and mysql++, i have installed mysql server, it is running fine. i also installed "mysql++-1.7.9gcc3.2-2.i386.rpm" (i have gcc 3.3) , first of all as the readme file says to do...
3
by: Gandu | last post by:
Could some C++ guru please help me? I have a very odd problem with respect templates and inheritance. I have templatized List class, from which I am inheriting to create a Stack class. All works...
7
by: Hendrik Schober | last post by:
Hi, I have a problem, that boils down to the following code: #include <iostream> #include <typeinfo> class Test1 {}; class Test2 {}; class Test3 {};
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
0
by: Jon Slaughter | last post by:
I'm having a big problem(its probably simple but I just can't seem to figure it out). I have a Node template: template <unsigned int I, unsigned int J, typename T> struct Node { enum {i =...
5
by: Hari | last post by:
Guys please help me to solve this strange problem what Iam getting as follows.. Trying to instantiate a global instance of a template class as follows :- when i build this code with debug and...
2
by: Sherrie Laraurens | last post by:
Hi all, I'm trying to write a generic algorithm routine that will take begin and end iterators of a container, iterate through the range and perform a "calculation" of sorts. The trouble is...
7
by: StephQ | last post by:
First of all: distinction of keywords typename and class in template arguments. Accoarding to a post in a well known moderated group: "There are three possibilities for template arguments: 1)...
3
by: StephQ | last post by:
I'm writing some algorithms that works on generic functions using boost::bind. My problem is that class templates can never be deduced. In the simplest cases I just write the class like: ...
3
by: knkk | last post by:
I am trying to include this code in the footer.template files of all blog templates: <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." :...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.