[LC++]Default Arguments

Jack Lloyd lloyd at acm.jhu.edu
Sat May 11 02:37:05 UTC 2002


On Fri, 10 May 2002, Mark Phillips wrote:

> Jack Lloyd wrote:
>
>
> > class Y
> >    {
> >    public:
> >       const X* x;
> >       void foo() { printf("%d\n", x->foo); }
> >       Y(X* xx = new X(42)) : x(xx) {}
> >    };
>
>
> Not quite an answer to your question, but...
>
> Wouldn't the above be a memory leak?  "X(42)" would not get
> deleted.

Oh. Well yeah, I suppose it would in this case. Presumably real code would
have destructors to delete x. -J





More information about the tuxCPProgramming mailing list