template probleme

Discussion in 'C++' started by yomgui, Mar 28, 2005.

  1. yomgui

    yomgui Guest

    Hi,

    The following code compiles on Unix but refuse to do so with devstudio6

    can anyone help me to get it right ? (ie for visual studio)


    template <class T> class AutoPtr
    {
    public:
    /** Default constructor. */
    AutoPtr(T* p = 0);

    /** Copy contructing an AutoPtr from another AutoPtr causes the old
    one
    * to be released from destruction duty. */
    AutoPtr(const AutoPtr &a);

    /** Copy contructing an AutoPtr from a pointer with a different element
    type. */
    template<class T1> AutoPtr(const AutoPtr<T1> &a);
    }

    devstudio says: member function already defined or declared
    on the last constructor

    thanks

    yomgui
    yomgui, Mar 28, 2005
    #1
    1. Advertising

  2. On 2005-03-28, yomgui <> wrote:
    > Hi,
    >
    > The following code compiles on Unix but refuse to do so with devstudio6
    >
    > can anyone help me to get it right ? (ie for visual studio)
    >
    >
    > template <class T> class AutoPtr
    > {
    > public:
    > /** Default constructor. */
    > AutoPtr(T* p = 0);
    >
    > /** Copy contructing an AutoPtr from another AutoPtr causes the old
    > one
    > * to be released from destruction duty. */
    > AutoPtr(const AutoPtr &a);
    >
    > /** Copy contructing an AutoPtr from a pointer with a different element
    > type. */
    > template<class T1> AutoPtr(const AutoPtr<T1> &a);
    > }
    >
    > devstudio says: member function already defined or declared
    > on the last constructor


    Looks like an issue with the compiler -- the parameterized constructor is
    *not* a copy constructor.

    Here's a question for you -- what is the output of this code on your compiler ?
    The template constructor should not be called on copy -- the compiler should
    still create one.

    /*
    template construct ...
    conversion construct called!
    calling copy construct ...
    */

    #include <iostream>

    class X {
    public:

    template <typename T> X(const T& ) {
    std::cout << "conversion construct called!" << std::endl;
    }
    };


    int main()
    {
    std::cout << "template construct ... " << std::endl;
    X x(3);
    std::cout << "calling copy construct ... " << std::endl;
    X y(x);
    }


    Cheers,
    --
    Donovan Rebbechi
    http://pegasus.rutgers.edu/~elflord/
    Donovan Rebbechi, Mar 28, 2005
    #2
    1. Advertising

  3. yomgui wrote:
    > The following code compiles on Unix but refuse to do so with devstudio6
    >
    > can anyone help me to get it right ? (ie for visual studio)


    You will have to upgrade your compiler to 7.1 or 8.0 Beta in order to
    make it work. VC++ v6 is notoriously bad with member templates.

    > [...]
    Victor Bazarov, Mar 28, 2005
    #3
  4. yomgui

    yomgui Guest

    I've tried your test,
    this is also my result:

    > template construct ...
    > conversion construct called!
    > calling copy construct ...


    yomgui
    yomgui, Mar 29, 2005
    #4
    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.
Similar Threads
  1. sdffsdf

    Probleme de lecture de champs BDD

    sdffsdf, Apr 7, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    900
    Ken Cox [Microsoft MVP]
    Apr 7, 2005
  2. Andreas

    Probleme mit LoadControl

    Andreas, Mar 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    540
    =?Utf-8?B?bWVuc3V1cg==?=
    Mar 4, 2006
  3. christian Ginouvet

    Probleme d'affichage de couleur d'arriere plan

    christian Ginouvet, Nov 10, 2003, in forum: Java
    Replies:
    0
    Views:
    554
    christian Ginouvet
    Nov 10, 2003
  4. Kristiansem
    Replies:
    0
    Views:
    1,105
    Kristiansem
    Mar 3, 2004
  5. Kristiansem
    Replies:
    0
    Views:
    328
    Kristiansem
    Mar 3, 2004
Loading...

Share This Page