Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > explicit invocation of a constructor template of a class template

Reply
Thread Tools

explicit invocation of a constructor template of a class template

 
 
benben
Guest
Posts: n/a
 
      02-15-2006
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
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      02-15-2006
* 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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to call an inherited, template class constructor from initializerlist of an inheriting, non-template class constructor l.s.rockfan@web.de C++ 4 11-15-2008 01:22 PM
how to call an inherited, template class constructor from initializerlist of an inheriting, non-template class constructor l.s.rockfan@web.de C++ 2 11-14-2008 10:04 PM
derived class incresing the sopce of base class methods and explicit call to constructor Taran C++ 6 04-20-2006 06:26 PM
What's the difference betwwen explicit instantiaion and explicit specialization? Andy C++ 5 01-30-2005 11:46 PM
Is explicit template qualification required for explicit delete? J.T. Conklin C++ 1 08-11-2004 02:06 AM



Advertisments