Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Please comment on the code

Reply
Thread Tools

Please comment on the code

 
 
sci
Guest
Posts: n/a
 
      04-13-2004
For B to call back a member of A, the code is design as:

class A;

class B
{
A* p;
public:
void Init(void* m) { p = (A*)m; }
void docallback();
};


class A
{
B b;
public:
A() { b.Init(this); }
void dowork() { }

};


void B::docallback()
{
((A*)p)->dowork();
}

Thanks!


 
Reply With Quote
 
 
 
 
Kevin Goodsell
Guest
Posts: n/a
 
      04-13-2004
sci wrote:
> For B to call back a member of A, the code is design as:
>
> class A;
>
> class B
> {
> A* p;
> public:
> void Init(void* m) { p = (A*)m; }


C-style casts are evil. Why didn't you just make Init take a A*?

> void docallback();
> };
>
>
> class A
> {
> B b;
> public:
> A() { b.Init(this); }
> void dowork() { }
>
> };
>
>
> void B::docallback()
> {
> ((A*)p)->dowork();


Why are you casting p to the type it already is?

> }
>


-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exchange calendar to Ruby object. Please comment the code. Damjan Rems Ruby 0 03-16-2007 09:36 AM
Please comment on my integer to string code. manoj1978@gmail.com C++ 58 03-15-2006 02:44 PM
Please Comment on this Integer to String Code. manoj1978@gmail.com C Programming 7 03-10-2006 11:32 PM
HOLD warning? Please comment on my code! Analog_Guy VHDL 6 06-01-2005 05:16 PM
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM



Advertisments