VisualC++'s warning C4355 (Was [win] wxExecute() and activation)

2 views
Skip to first unread message

Rob OConnor

unread,
Sep 2, 2002, 12:40:03 PM9/2/02
to wx-u...@lists.wxwindows.org
Here is an archive of a comp.std.c++ thread about this
warning and what potential problem it is warning
about. I make no assertion, however, that the info
here is right or not ;-)

http://cpptips.hyperformix.com/cpptips/pre_this

For wxTimer though and Borland C++ is does seem to
make a difference. I was using a wxTimer, and was
using this code snippet from the statbar example:

//----------------------------------
#ifdef __VISUALC__
// 'this' : used in base member initializer list
-- so what??
#pragma warning(disable: 4355)
#endif

MyStatusBar::MyStatusBar(wxWindow *parent)
: wxStatusBar(parent, -1), m_timer(this),
m_checkbox(NULL)
//-------------------------------------

In Borland's BCC though, when I used this in my frame,
the application would blow up with memory trashing
when I was closing the application (I believe they
were ones saying 'All bets are off!' or something like
that).
If I replaced the
m_timer(this)
of the initiazlizer, with a
m_timer.SetOwner(this);
inside the constructor function, then things would
then run perfectly.

I don't know BCC very well, nor portability of such
initializers in a compiler-agnostic context. I think I
may add it as a wxWiki note anyways though, because it
may have been very tough for a newcomer to track down
the reason for this kind of problem.

Best wishes,
Robert

__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

Vadim Zeitlin

unread,
Sep 2, 2002, 9:45:03 PM9/2/02
to wx-u...@lists.wxwindows.org
On Mon, 2 Sep 2002 16:38:29 -0700 (PDT) Rob OConnor <rob...@yahoo.com> wrote:

RO> Here is an archive of a comp.std.c++ thread about this
RO> warning and what potential problem it is warning
RO> about. I make no assertion, however, that the info
RO> here is right or not ;-)
RO>
RO> http://cpptips.hyperformix.com/cpptips/pre_this

It is right but irrelevant :-) I.e. it's true that if you have

class B { public: virtual void Do(); };
class Foo { public: Foo(B *b) { b->Do(); };
class D : public B
{
public:
public: D() : m_foo(this) { }

virtual void Do();

private:
Foo m_foo;
};

you also have a bug as B::Do() is called in the ctor of Foo, not D::Do() as
might have been expected. However:

1. in wxTimer case ctor doesn't use the pointer at all, just stores it
2. you could just as well change D::D() to do m_foo.Set(this) in the body
of the ctor instead of using the initializer list and you'd still have
the bug

So IMNSHO this warning is pretty stupid.

RO> For wxTimer though and Borland C++ is does seem to
RO> make a difference. I was using a wxTimer, and was
RO> using this code snippet from the statbar example:
RO>
RO> //----------------------------------
RO> #ifdef __VISUALC__
RO> // 'this' : used in base member initializer list
RO> -- so what??
RO> #pragma warning(disable: 4355)
RO> #endif
RO>
RO> MyStatusBar::MyStatusBar(wxWindow *parent)
RO> : wxStatusBar(parent, -1), m_timer(this),
RO> m_checkbox(NULL)
RO> //-------------------------------------
RO>
RO> In Borland's BCC though, when I used this in my frame,
RO> the application would blow up with memory trashing
RO> when I was closing the application (I believe they
RO> were ones saying 'All bets are off!' or something like
RO> that).
RO> If I replaced the
RO> m_timer(this)
RO> of the initiazlizer, with a
RO> m_timer.SetOwner(this);
RO> inside the constructor function, then things would
RO> then run perfectly.

Sorry, I can't believe it could have been related to this. These lines are
completely equivalent!

Regards,
VZ


Reply all
Reply to author
Forward
0 new messages