473,589 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

explicit specialization od c'tor

// variable creation object
template <class T> class CL
{
public:
CL (const T& t) {}
template <> CL<double>(cons t T& t) {}
};

How do I make a constructor for T = double, ..., so I can distinguish
between the types.

Thank you,

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%c gl%ssic%ccom%c" , "ma", 58, 'g', 64, "ba", 46, 10);}

_______________ _______________ __________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
Jul 22 '05 #1
11 1974

"Gernot Frisch" <Me@Privacy.net > skrev i en meddelelse
news:35******** *****@individua l.net...
// variable creation object
template <class T> class CL
{
public:
CL (const T& t) {}
template <> CL<double>(cons t T& t) {}
};

How do I make a constructor for T = double, ..., so I can distinguish
between the types.
Simply have the constructor untemplated:

template <class T> class CL
{
public:
CL (const T& t) {}
CL(double t) {}
};

/Peter
Thank you,

--
-Gernot
int main(int argc, char** argv) {printf ("%silto%c%cf%c gl%ssic%ccom%c" ,
"ma", 58, 'g', 64, "ba", 46, 10);}

_______________ _______________ __________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com

Jul 22 '05 #2
Gernot Frisch wrote:
// variable creation object
template <class T> class CL
{
public:
CL (const T& t) {}
template <> CL<double>(cons t T& t) {}
};

How do I make a constructor for T = double, ..., so I can distinguish
between the types.

I cannot think of another way...
template <>
class CL<double>
{
public:
CL (const double& t) {}
};


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #3
Peter Koch Larsen wrote:
Simply have the constructor untemplated:

template <class T> class CL
{
public:
CL (const T& t) {}
CL(double t) {}
};

This does not work.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #4
Gernot Frisch wrote:
// variable creation object
template <class T> class CL
{
public:
CL (const T& t) {}
template <> CL<double>(cons t T& t) {}
};

How do I make a constructor for T = double, ..., so I can distinguish
between the types.
...


If you want to provide the explicit specialization for the constructor
alone you simply define it as follows

template<class T> class CL
{
CL(const T& t) {}
};

template<> CL<double>::CL( const double& t)
{
// Specialized implementation goes here
}

--
Best regards,
Andrey Tarasevich
Jul 22 '05 #5
Andrey Tarasevich wrote:
If you want to provide the explicit specialization for the constructor
alone you simply define it as follows

template<class T> class CL
{
public:
CL(const T& t) {}
};

template<> CL<double>::CL( const double& t)
{
// Specialized implementation goes here
}

Pretty cool. How can we provide the declaration in this style?


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #6
Ioannis Vranos wrote:
Andrey Tarasevich wrote:
If you want to provide the explicit specialization for the constructor
alone you simply define it as follows

template<class T> class CL
{

public:
CL(const T& t) {}
};

template<> CL<double>::CL( const double& t)
{
// Specialized implementation goes here
}


Pretty cool. How can we provide the declaration in this style?


What for? The original template definition already contains a declaration
anybody would need...
Jul 22 '05 #7
Ioannis Vranos wrote:

Pretty cool. How can we provide the declaration in this style?

I just noticed that this

template<class T> class CL
{
public:
CL(const T& t) {}
};
// Declaration
template<>
CL<double>::CL( const double& t);
template<>
CL<double>::CL( const double& t)
{
// Specialized implementation goes here
}
int main()
{
CL<double> a(2);
}
compiles.

Pretty weird style.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #8
Victor Bazarov wrote:
What for? The original template definition already contains a declaration
anybody would need...

For whatever reason (export may be? - or something else). :-)

Anyway as I say in another message I just sent, probably I found the
declaration style. Pretty weird stuff.
I am not sure TC++PL mentions this style, or I have forgotten.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #9
Ioannis Vranos wrote:
Victor Bazarov wrote:
What for? The original template definition already contains a
declaration
anybody would need...


For whatever reason (export may be? - or something else). :-)

Anyway as I say in another message I just sent, probably I found the
declaration style. Pretty weird stuff.
I am not sure TC++PL mentions this style, or I have forgotten.


You can think of every function _definition_ as consisting of
a declaration and a body. So, if you already have a definition, just
replace the body with a semicolon :-)
Jul 22 '05 #10

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

Similar topics

12
4740
by: Marcelo Pinto | last post by:
Hi all, In practice, what is the diference between a default constructor and an explicit default constructor? class Ai { public: Ai() {} };
4
1829
by: CoolPint | last post by:
I would be grateful if someone could point out if I am understanding correctly and suggest ways to improve. Sorry for the long message and I hope you will kindly bear with it. I have to make it elaborate to make sure my questions are clear enough. Let's say I need to write a function whose logic is same for all types (T) except in the case of T * (including const T *). Furtheremore , the function needs to be written differently for...
8
2969
by: trying_to_learn | last post by:
Why do we need to explicitly call the copy constructor and the operator = , for base class and member objects in composition? ....book says "You must explicitly call the GameBoard copy-constructor or the default constructor is automatically called instead" Why cant the compiler do this on its own. if we are making an object through copr construction for an inherited class , then why not simply call the corresponding copy constructors for...
5
2229
by: Andy | last post by:
Hi, I got a little confused on 'instantiation' and 'specialization', espcially for explicit instantiation and explicit sepcialization. Can anybody explain the difference? Thanks a lot! Andy
8
4787
by: Ferdi Smit | last post by:
I've never understood the rationale of allowing partial, but not explicit specialization for classes at non-namespace scope. Ie.: struct A { template <typename T1, typename T2> struct B {}; // this is not allowed: template <> struct B<int, float> {};
1
1515
by: Thomas Barnet-Lamb | last post by:
I have a query concerning the handling of explicit specializations. Essentially, I want to know whether it is legal to take a template like >template<class X> typename X::A Foo(typename X::B, typename X::C) and specialise it in the case X takes some particular value, such as: >template<> typename Bar::A Foo<Bar>(typename Bar::B, typename Bar::C)
1
1978
by: ranges22 | last post by:
****************************************************************** I am compiling a librarry which has a .h file containing th following: ****************************************************************** template<typename T> void from_string(const char Str, T &Obj); template<> void from_string(const char Str, long &); // template<> void from_string(const char Str, unsigned lon &); //
2
7685
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
0
2909
by: greek_bill | last post by:
Hi, I have a template function for which I use SFINAE to restrict one of the parameters. Then I also have a partial specialization of this function.I would like to provide an explicit instantiation of the partially specialized version, but my compiler (VC8) complains because it fails the SFINAE version. I just realized as I was typing this that I'm using partial _function_ specialization. I'm sure I remember reading somewhere that
0
7931
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7865
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8233
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8224
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3849
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3889
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1461
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.