Andre Poenitz <[EMAIL PROTECTED]> writes: | On Tue, Mar 12, 2002 at 12:28:10AM +0100, Lars Gullik Bjønnes wrote: >> | Can you please give an example for the brain dead amongst us ? >> >> class Foo { >> // unsafe variant >> Foo() >> : bar1(new Bar), bar2(new Bar) >> {} >> // safer variant >> Foo() { >> bar1 = new Bar; >> bar2 = new Bar; >> } >> private: >> Bar * bar1; >> Bar * bar2; >> }; > | Bad example. No class should contain more than one raw 'owned' pointer | is a better rule...
And _way_ harder to enforce..., and also please explain why this is a bad example? And why shouldn't a class contain more than one pointer? Does this one suid you better: class Foo { // unsafe Foo() : bar(new Bar), str(10, 'n') {} // safeer Foo() : str(10, 'n') { bar = new Bar; } private: Bar * bar; string str; }; Now the str allocation throws. -- Lgb