Re: Question about C++ (please, answer)
- From: "John R. Sheets" <dusk ravendusk org>
- To: gnome-devel-list gnome org
- Subject: Re: Question about C++ (please, answer)
- Date: Thu, 25 Jan 2001 13:15:53 -0600
On Jan 25, 2001, Eric Jung <whp applware com> wrote:
>
> Hi, everyone.
>
> I have a simple (or complex) c++ question.
Well, this isn't the proper forum for straight C++ questions, although
I'm not sure where you _would_ ask (maybe on IRC?). gnome-devel is
for GNOME-specific questions. Nevertheless, in the spirit of good
samaritanism...
> > The below source code do not be compiled and make errors.
> I really don't know why. Maybe I'm too foolish -_-;
> I'll wating for your answering. Thanks so much.
The problem is in your derived class. You don't need to access
inherited members through the 'this' pointer; 'this' is implied. When
you cast 'this', I suppose g++ treats it like an external reference
(i.e., public only). Visual C++ might allow this. Just a hunch.
> class Button : public Widget
> {
> protected:
> void draw()
> {
> ((Widget*)this)->_i++;
> ((Widget*)this)->draw();
> }
> };
Try something like this instead, using explicit scoping to call the
Widget version of draw():
--- test.orig.cc Thu Jan 25 10:27:55 2001
+++ test.cc Thu Jan 25 10:27:17 2001
@@ -10,8 +10,8 @@
protected:
void draw()
{
- ((Widget*)this)->_i++;
- ((Widget*)this)->draw();
+ _i++;
+ Widget::draw();
}
};
John
--
dusk ravendusk org http://www.gnome.org
jsheets codeweavers com http://www.worldforge.org
jsheets users sourceforge net http://openbooks.sourceforge.net
http://advogato.org/person/jsheets
Writing Gnome Applications
http://www.aw.com/cseng/titles/0-201-65791-0/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]