Topic: Use of templated copy ctor in derived classes


Author: "Pavel Kuznetsov" <pavel.kuznetsov@gmail.com>
Date: 5 Aug 2005 18:00:31 GMT
Raw View
Roger,

 r> class Base
 r> {
 r> public:
 r>    Base() {}

 r>    template< typename T>
 r>    Base( const T & v )
 r>    {
 r>       std::cout << "base template ctor for: " << typeid( v ).name() <<
 r> std::endl;
 r>    }

 r>    Base( const Base & rhs )
 r>    {
 r>       std::cout << "base copy ctor" << std::endl;
 r>    }
 r> };

 r> class Derived : public Base
 r> {
 r> };

 r> int main()
 r> {
 r>    Derived object;

 r>    Derived another(object);
 r> }

 r> I would expect the program to produce:
 r> "base copy ctor"
 r> as output - and g++ 3.2.3 does this.

 r> However, MSVC 7.1 produces:
 r> "base template ctor for: class Derived"

 r> I believe VC is wrong here - but have I missed something?

Including yours there are three bug reports for this VC++ bug:
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=6e00fb7a-9521-4df5-ac05-a089a7df909a
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=997157bb-3ad1-473e-a5df-8043fecac90e
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=c450daa9-e41f-4fd0-9c60-822a6c4d058d

I consider the last one to be the best among all of these since it does not even use templates.

--
Pavel

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rogero@howzatt.demon.co.uk
Date: 29 Jul 2005 16:50:29 GMT
Raw View
Hello,
plea for a sanity check.

In 12.8 Copying class objects [class.copy] we have:

p2 - a template ctor is never a copy ctor
p8 - [The implicitly-defined copy constructor]
.if the subobject is of class type, the copy constructor for the
class is used

Consider the following code:

#include <iostream>
#include <typeinfo>

class Base
{
public:
   Base() {}

   template< typename T>
   Base( const T & v )
   {
      std::cout << "base template ctor for: " << typeid( v ).name() <<
std::endl;
   }

   Base( const Base & rhs )
   {
      std::cout << "base copy ctor" << std::endl;
   }
};

class Derived : public Base
{
};

int main()
{
   Derived object;

   Derived another(object);
}

I would expect the program to produce:
"base copy ctor"
as output - and g++ 3.2.3 does this.

However, MSVC 7.1 produces:
"base template ctor for: class Derived"

I believe VC is wrong here - but have I missed something?

Regards,
Roger Orr
--
MVP in C++ at www.brainbench.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]