octave-maintainers
[Top][All Lists]
Advanced

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

Re: c++ question


From: Shai Ayal
Subject: Re: c++ question
Date: Mon, 12 Oct 2009 22:49:21 +0200

On Mon, Oct 12, 2009 at 9:00 AM, Shai Ayal <address@hidden> wrote:
> On Mon, Oct 12, 2009 at 8:37 AM, Jaroslav Hajek <address@hidden> wrote:
>> On Sun, Oct 11, 2009 at 10:55 PM, Shai Ayal <address@hidden> wrote:
>>> Hi all,
>>>
>>> This is a question I came across while trying to work on opengl
>>> backend. At first I thought it was too trivial to ask on the list, so
>>> I asked Michael privately, but since he agrees that it is strange, I
>>> gained some self confidence and so I'm asking on the list :)
>>> I am using gcc version 4.3.4 (Debian 4.3.4-5).
>>>
>>> Any help would be apriciated. The definitions of the opengl_renderer
>>> class are in src/gl-render.h
>>>
>>> Shai
>>>
>>> On Sat, Oct 10, 2009 at 8:55 PM, Shai Ayal <address@hidden> wrote:
>>>> On Sat, Oct 10, 2009 at 10:35 AM, Shai Ayal <address@hidden> wrote:
>>>>> Hi Michael,
>>>>>
>>>>> I'm trying to implement the gl2ps code in the gl-renderer, and I've
>>>>> come across a c++ problem:
>>>>> As a first step I tried to defined a subclass of opengl_render which
>>>>> should override the draw method for a handle. In the new method gl2ps
>>>>> will be initialized. This is the definition:
>>>>> #include "gl-render.h"
>>>>>
>>>>> class
>>>>> OCTINTERP_API
>>>>> glps_renderer : public opengl_renderer
>>>>> {
>>>>>  public:
>>>>>  glps_renderer (const std::string& _filename)
>>>>>    : opengl_renderer () , filename (_filename) { }
>>>>>
>>>>>  ~glps_renderer (void) { }
>>>>>
>>>>>  void draw (const graphics_object& go);
>>>>>
>>>>>  private:
>>>>>  std::string filename;
>>>>>
>>>>> };
>>>>>
>>>>> However, when I try to use this in the code:
>>>>>
>>>>>        glps_renderer gl2ps (print_filename);
>>>>>        gl2ps.draw (gh_manager::lookup (number));
>>>>>
>>>>> The compiler complains that there is no matching function for call to
>>>>> ‘glps_renderer::draw(graphics_handle).
>>>>>
>>>>> I thought it would automatically use the base class
>>>>> opengl_render::draw(graphics_handle) which would then call
>>>>> glps_renderer::draw (const graphics_object& go);
>>>>>
>>>> OK, I think I figured it out :
>>>> opengl_renderer *rend = new glps_renderer (print_filename);
>>>> rend->draw (gh_manager::lookup (number));
>>>>
>>>> so it appears the compiler is able to do run time dynamic functions,
>>>> but not compile time. Strange.
>>>>
>>
>> No, it would work the same if the methods were non-virtual, it plays
>> no role. What you see is a bit unknown C++ feature called "name
>> hiding". In short, methods from base class are not automatically
>> imported into the subclass namespace if there's an overloaded version
>> declared in the subclass. (Trust me, there are good reasons for this).
>>
>> You can either import it explicitly:
>>
>> class
>> OCTINTERP_API
>> glps_renderer : public opengl_renderer
>> {
>>  public:
>>   using opengl_renderer::draw;
>>  glps_renderer (const std::string& _filename)
>>   : opengl_renderer () , filename (_filename) { }
>>
>>  ~glps_renderer (void) { }
>>
>>  void draw (const graphics_object& go);
>>
>>  private:
>>  std::string filename;
>>
>> };
>>
>> to the public section of gpls_renderer,
>>
>> or make the call like this:
>>
>>  glps_renderer gl2ps (print_filename);
>>  gl2ps.opengl_renderer::draw (gh_manager::lookup (number));
>>
>>
>>>> Now for the next problem:
>>>> the opengl_renderer::draw function is actually a dispatcher based upon
>>>> the object type. The way I implemented the gl2ps renderer, I override
>>>> the draw method, do the gl2ps initializations and then call
>>>> opengl_renderer::draw.
>>>> The problem is I would like to override some specific draw function
>>>> (e.g.  virtual void draw (const text::properties& props);), but
>>>> instead of the glps_renderer version being called, the base
>>>> opengl_renderer version is called. So when calling with a text object
>>>> the sequence is:
>>>>
>>>> opengl_renderer::draw (const graphics_handle& h)
>>>> glps_renderer::draw (const graphics_object& go);
>>>> opengl_renderer::draw (const graphics_object& go);
>>>> opengl_renderer::draw (const text::properties& props)
>>>>
>>>> although there is a glps_renderer::draw (const text::properties& props)
>>>>
>>>> Any thoughts?
>>>
>>
>> Please post your code, or a (not working) changeset. I'd like to help,
>> but I need more info.
>>
> Thanks Jaroslav. I'll try to post some code tonight

OK, it was my mistake. I found my problem -- I was just
misunderstanding the opengl_renderer code.

Thanks and sorry for the noise

Shai



reply via email to

[Prev in Thread] Current Thread [Next in Thread]