octave-maintainers
[Top][All Lists]
Advanced

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

c++ question


From: Shai Ayal
Subject: c++ question
Date: Sun, 11 Oct 2009 22:55:13 +0200

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.
>
> 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?

Both problems are really weird. Basically, this *should* work
as you expect. For the first problem, you might try to use an
intermediate variable to store the graphics_handle object,
although I don't expect any difference. For the second problem,
I have no clue. Sorry.

Michael.



reply via email to

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