|
Boost : |
From: mred_at_[hidden]
Date: 2001-07-09 20:48:06
I really wanted the templated shared_ptr assignment and constructor
turned on for MSVC++ 6.0 in this latest boost release. But in the
following program, MSVC++ 6.0 SP5 skips right over the first
assignment to share_ptr! (It does not emit assembly for it.)
Should MSVC++ fail to compile the first assignment, or should it
automatically instantiate "shared_ptr<int>"?
Even scarier, you can add "p = new char;" and it compiles.
-Ed-
-=-=-=-=-
#include <boost/smart_ptr.hpp>
#include <iostream>
template <typename T>
struct A {
A( int ) {}
template <typename U> A<T>& operator = (const A<U>& that) {
std::cout << "works" << std::endl;
return *this;
}
template <> A<T>& operator = (const A<T>& that) {
std::cout << "works" << std::endl;
return *this;
}
};
int main() {
boost::shared_ptr<int> p;
p = new int; // MSVC++ 6.0 will skip this line!
p = boost::shared_ptr<int>(new int); // will work
A<int> q(0);
q = A<int>(1); // will work
q = A<char>(1); // will work
q = int(); // MSVC++ 6.0 will skip this line!
q = char(); // MSVC++ 6.0 will skip this line!
return 0;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk