473,322 Members | 1,690 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.

Templatized constructor

If I had a class with a templatized constructor, like this:

Expand|Select|Wrap|Line Numbers
  1. class foo
  2. {
  3.   public:
  4.     template<typename T> foo();
  5. };
  6.  
then how could I explicitly specify the type of T? Calling foo(1) deduces T to be int, but what if I wanted it to be double? How could I specify non-type template parameters, as in:

Expand|Select|Wrap|Line Numbers
  1. class bar
  2. {
  3.   public:
  4.     template<int n> bar();
  5. };
  6.  
Dec 10 '06 #1
1 1845
Hi tavianator!

You can't do this, there is no way to provide an explicit template argument list for constructor function templates.

See C++ standard §14.8.1

/jz
Dec 10 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: hall | last post by:
I have a problem with my design of a templatized class. I'm trying to figure out how to load and save the data inside it, but can't. My class looks like this ------------------------------------...
3
by: ma740988 | last post by:
Consider the template member function that generates a random number within a range. #include <cstdlib> #include <ctime> #include <iostream> template<typename T> T Random(T bottom, T top) {
1
by: aurgathor | last post by:
Howdy, I got the templatized class Matrix working in the way it's written in the faq , and it works fine as: Matrix<sqr_T> display(80,25); However, I'd like to have this variable in the...
5
by: mrstephengross | last post by:
Ok, I've got code that looks something like this: ================================================== template<typename T1, typename T2> class Base { public: explicit Base(const T1 & t1) {...
3
by: lhr_cool_guy | last post by:
The following code is compiling correctly on Visual Studio .NET 2003 but crashes. The problem is that the copy constructor is not being called when it should be. Am I doing something wrong or is...
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
1
by: StephQ | last post by:
I can't get this code working: class Scheme_euler { private: .... public: ....
3
by: gary.bernstein | last post by:
I want to call a singleton getInstance function to retrieve a templatized object without knowing what types were used to create the singleton object in the first call to getInstance. How can I do...
4
by: Zachary Turner | last post by:
Is it possible to declare a class with a templatized constructor? I was sure it was, but GCC is giving me errors when I try to do this. Most likely user error. Some example code is: class...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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: 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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.