explicit invocation of a constructor template of a class template

Discussion in 'C++' started by benben, Feb 15, 2006.

  1. benben

    benben Guest

    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
    benben, Feb 15, 2006
    #1
    1. Advertising

  2. * 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?
    Alf P. Steinbach, Feb 15, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page