Re: Design question related to std::auto_ptr
On Mar 23, 11:10 am, Vladimir Jovic <vladasp...@gmail.com> wrote:
Alf P. Steinbach wrote:
[...]
Some folks have argued that the same technique must in
practice have to work nicely also for std::auto_ptr, at
least if also Foo::~Foo() is defined in the implementation
file, because how could any compiler manage to screw up
things then? But according to the standard's general rules
it's just UB to do it with std::auto_ptr. And one risks the
compiler warning about that UB, as above.
On my compiler (g++ 4.1.2), modifying the example to this:
//start-snip
#include<memory>
class Details;
class MyConcrete {
private:
std::auto_ptr<Details> details_;
};
int main() {
MyConcrete obj;
return 0;
}
class Details
{};
// end-snip
everything compiles fine (without warning). Am I causing UB in
any way?
Formally, yes. Put the definition of Details in another
translation unit, and g++ complains. It probably doesn't here
due to an artifact of the way it instantiates templates---I
think it parses the complete file before instantiating any
templates. And having seen the complete file, it knows the
structure of Details.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34