explicit invocation of a constructor template of a class template

B

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?

Or is it really a very silly question?

Regards,
Ben
 
A

Alf P. Steinbach

* 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top