Re: auto_ptr who is right?
BobR wrote:
Barry <dhb2000@gmail.com> wrote in message...
sorry, I didn't compile this code, I just make a mimic example
after I post this thread, I compile this code (add return), and found it
work also on MSVC8
Well, this one really crashes!
#include <memory>
#include <iostream>
#include <string>
using namespace std;
struct Pizza{
Pizza(string const& name) : name_(name) {}
void Show() const {
cout << name_ << " Pizza" << endl;
}
private:
string name_;
};
<snip unused 'Pie' >
class AbstractFactory{ public:
virtual auto_ptr<Pizza> CreatePizza() = 0;
virtual ~AbstractFactory() {}
};
class NestFactory : public AbstractFactory {
virtual auto_ptr<Pizza> CreatePizza(){
// return new Pizza( "Nest" );
// error: conversion from `Pizza*' to non-scalar type
// `std::auto_ptr<Pizza>' requested
return std::auto_ptr<Pizza>( new Pizza( "Nest" ) );
Thanks for your reply, can you tell me where in the standard talk about
this?
And more, why the example in the OP works with MSVC8 while this one does
NOT?
And why all cases works well with STLPort? Is this a bug in STLPort's
auto_ptr?
}
};
int main(){
auto_ptr<AbstractFactory> pFactory(new NestFactory);
auto_ptr<Pizza> pPizza = pFactory->CreatePizza();
pPizza->Show();
}
--
Thanks
Barry