(new MyRawBitmapFrame(this))->Show();

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
l13
Earned a small fee
Earned a small fee
Posts: 13
Joined: Mon Jan 02, 2006 12:08 am

(new MyRawBitmapFrame(this))->Show();

Post by l13 » Mon Jan 09, 2006 2:37 am

i

ssigala
Earned some good credits
Earned some good credits
Posts: 109
Joined: Fri Sep 03, 2004 9:30 am
Location: Brescia, Italy

Post by ssigala » Mon Jan 09, 2006 10:42 am

Sorry, but I don't understand your question. The line:

Code: Select all

(new MyRawBitmapFrame(this))->Show();
is valid C++ code. This is exactly the same as writing:

Code: Select all

MyRawBitmapFrame *p = new MyRawBitmapFrame(this);
p->Show();
But I agree that the former is not (IMHO) good readable style.
Sandro Sigala - Kynosoft, Brescia

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Re: (new MyRawBitmapFrame(this))->Show();

Post by upCASE » Mon Jan 09, 2006 10:53 am

l13 wrote:error C2059: syntax error : 'new'
can anyone explain to me what that line is all about?!
Could you give the complete compiler log and what compiler you use?
This is not really an error, as it is valid C++ code, though bad style...

The code simply creates an instance on the heap, but omits storing a pointer to is. Normaly you don't want that as this implies that you won't be able to access the instance after the call. It's "bad style" you can't even delete the instance. One might argue now that when using wxWidgets you don't need to delete the instance yourself, as long as it derived from wxObject, which would lead to deleting it "automatically" once the library exits. Still, IMHO, one shouldn't do that unless you're really sure that you'll never need access to the instance and that you won't be getting memory leaks doing so...
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

Post Reply