Re: Question about C++ (please, answer)

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

> > 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():

---        Thu Jan 25 10:27:55 2001
+++     Thu Jan 25 10:27:17 2001
@@ -10,8 +10,8 @@
     void draw()
-        ((Widget*)this)->_i++;
-        ((Widget*)this)->draw();
+        _i++;
+        Widget::draw();


dusk ravendusk org                  
jsheets codeweavers com        
jsheets users sourceforge net

                   Writing Gnome Applications

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]