This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Re: Forward declaration is not possible
On Tue, Dec 17, 2002 at 05:13:19PM +0100, Peter Haase wrote:
> Hi Brian,
> I'm writing a library* that provides some functions that are useful for
> developing simulation programs. For that reason I programmed a class called
> RandomGenerator:
>
> //in myrandom.h:
> #include <gsl_rng.h>
>
> class RandomGenerator
> {
[deleted]
> };
[deleted]
>
> //in myrandom.h:
> // !This isn't needed anymore: #include <gsl_rng.h>!
>
> //Forward declaration:
> struct gsl_rng;
>
> class RandomGenerator
> {
[deleted]
> };
>
> Unfortunatley this forward declaration is not possible if gsl_rng is declared
> as follows:
>
> typedef struct {
> char* name;
> /*... */
> } gsl_rng;
>
> but the forward declaration is possible if gsl_rng is declared as follows:
>
> typedef struct gsl_rng {
> char* name;
> /*... */
> } gsl_rng;
>
> Note, that code that is already existing can be used with that declaration as
> it was before! I'm not shure if it is strict ANSI C to use gsl_rng as a name
> for the struct and as the name of the new type introduced by the typedef
> statement. But at least in C++ it is standard conform (see C++ ARM s. 106):
> 'A typedef may be used to redefine a name to refer to the type to which it
> already refers - even in the scope where the type was originally declared.
> For example:
> typedef struct s { /* */ } s;'
>
> *(actually I'm not writing a library, but I think that is a more common case.
> So look to it as an abstract example)
>
> Hope this makes it a bit more clearer, what I would like to do.
>
> Thanks,
> Peter
Hi,
First, my apologies in advance if I am wrong. I did not actually try the idea
that I am about to suggest. Why can you not do something like:
typedef struct gsl_rng gsl_rng_typedefed;
and then use gsl_rng_typedefed for your C++ class?
I do not mean to object to your proposed change, I have no idea what the
consequences of that would be, I am just trying to suggest a way for you to get
things going.
cheers,
ato