473,408 Members | 2,441 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,408 software developers and data experts.

explicit invocation of a constructor template of a class template

Say I have a class template:

template <typename T>
class myclass
{
public:

template <typename U>
myclass(void )
{
U u;
// do something with u
}
};

My question is how to construct a myclass<int> object using the
myclass<int>::myclass<float> constructor?

Or is it really a very silly question?

Regards,
Ben
Feb 15 '06 #1
1 2158
* benben:
Say I have a class template:

template <typename T>
class myclass
{
public:

template <typename U>
myclass(void )
{
U u;
// do something with u
}
};

My question is how to construct a myclass<int> object using the
myclass<int>::myclass<float> constructor?
Consider

class myclass
{
public:
myclass() {}
myclass( int = 0 ) {}
};

There's no way to default-construct an object of this class.

The answer to your question is the same.

Or is it really a very silly question?


No.
--
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?
Feb 15 '06 #2

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

Similar topics

2
by: Dave Theese | last post by:
Hello again, In the program below, the following line is of interest: bar.insert(make_pair(42, 17)); insert() expects a pair<foo<1>, foo<2> >. I'm giving it a pair <int, int>. But this is...
9
by: Tanmoy Bhattacharya | last post by:
Hi, This is a question about whether I am right that a particular syntactic sugar is missing in C++. Let me explain with an example. Let us say I have a class for complex numbers, and I want...
11
by: Gernot Frisch | last post by:
// variable creation object template <class T> class CL { public: CL (const T& t) {} template <> CL<double>(const T& t) {} }; How do I make a constructor for T = double, ..., so I can...
5
by: henkoo | last post by:
i want to explicit instantiate a member function of a class template, and got some error, can anyone give some advice to correct it? 3x complier: g++ 3.2 #include <iostream> #include...
9
by: Rennie deGraaf | last post by:
I'm writing a class similar to this: #include <iostream> using namespace std; template<class t> class Foo { private: class Bar {
1
by: petschy | last post by:
hello, i've run into an error when qualifying a copy ctor 'explicit'. the strange thing is that i get a compiler error only if the class is a template and declare the variable as X<Zx = y....
42
by: coder_lol | last post by:
Thanks everyone again for contributing to helping me clear C++ confusions. I did some serious reading on copy constructors and assignments and I think I've got a good handle on the memory stuff. ...
7
by: Protoman | last post by:
Is this an efficient way to integrate an explicit function of x from a to b: #include <iostream> using namespace std; class Integrate { public: Integrate(long double (*f)(long double&...
1
by: =?gb2312?B?wfXquw==?= | last post by:
Hi, folks, I am trying to make my copy constructor explicit, but when the scenario below comes into being, weird things happen. Here is the code snippet: #include <iostream> using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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...
0
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,...

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.