octave-maintainers
[Top][All Lists]
Advanced

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

Re: general c++ question


From: Shai Ayal
Subject: Re: general c++ question
Date: Sat, 30 Jun 2007 10:33:01 +0300

On 6/30/07, Michael Goffioul <address@hidden> wrote:
On 6/30/07, Shai Ayal <address@hidden> wrote:
> This is a general c++ question, but I came upon it while trying to
> patch octave, so I figured I'll try asking here:
>
> I want to declare a function returning the figure::figure_properties
> class. This function will have to be declared before
> figure::figure_properties is declared. This is usually done using
> forward declarations -- i.e. I would expect he following to work:
>
> class figure;
> class figure::figure_properties;
> figure::figure_properties test();
>
> however gcc comes back with the error:
> 'figure_properties' in class 'figure' does not name a type
> for both lines where figure::figure_properties is mentioned. Trying
> the following also does not work:
>
> class figure;
> class figure_properties;
> figure::figure_properties test();
>
> with the same error where figure::figure_properties is mentioned.
>
> any ideas besides moving figure_properties outside figure?

I'm not sure this is the actual problem you get (and I'm not a C++ expert),
but I think that you can only deal with pointers to forward-declared classes,
because the compiler does not know the object size when you use it.

For example:

class A;
A test(); /* probably not OK */
A* test(); /* OK */

I actually tried it and it is OK. In any case you are right in that it
is silly to pass the calss by value -- I should pass a reference:

figure::figure_properties& test();


In your case, you have the additional problem to forward-declare nested
classes; I've never tried that.


Yes -- this is my problem -- does anybody have a clue?


Michael.



reply via email to

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