ctor declaration question - C++ Topic is solved

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
wxND
In need of some credit
In need of some credit
Posts: 8
Joined: Mon Feb 23, 2009 11:48 am

ctor declaration question - C++

Post by wxND »

Hello together :)

I have a C++ language specific question.
I've come across the following declaration of a ctor while studing an example of the wxWidgets docu (see comment):

Code: Select all

class myCW : wxControl{
    myCW (){}; //default ctor

    myCW (/*some parameters here*/){
        Create(/*some parameters here*/);
    } bool Create(/*some parameters here*/);  //<-here, the bool Creat() in the ctor declaration ?

    virtual ~myCW (){}; //default dtor
    void Init();
};

void myCW::Init(){/*Do some stuff here*/}
What does this do ? ps: i shortened the code, just to have a better overview.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

they're unrelated, bool Create() is just another method declaration.

Code: Select all

myCW (/*some parameters here*/){
  Create(/*some parameters here*/);
}

bool Create(/*some parameters here*/);
However, unless you explicitly want to support two-step creation of your control, I'd suggest not to overwrite Create().
And if you do, make sure to call wxControl::Create() in it.
Last edited by doublemax on Mon Apr 06, 2009 2:43 pm, edited 1 time in total.
Use the source, Luke!
TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV »

Code: Select all

myCW (/*some parameters here*/){ 
        Create(/*some parameters here*/); 
    } bool Create(/*some parameters here*/);
I think a better re-read of this snippet is :

Code: Select all

myCW (/*some parameters here*/) {Create(/*some parameters here*/); }
bool Create(/*some parameters here*/);
Which declares two methods :
- myCW()
- Create()

Implementation of constructor myCW() is given, and makes use of Create().
I guess Create() implementation is given elsewhere.
wxND
In need of some credit
In need of some credit
Posts: 8
Joined: Mon Feb 23, 2009 11:48 am

Post by wxND »

Hey thank you guys - I appreciate every input :)

Sometimes one does not see the apparent ;)
Post Reply