www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/10/23:49:50

Message-ID: <316C715E.6512@public1.guangzhou.gd.cn>
Date: Thu, 11 Apr 1996 11:41:34 +0900
From: Wang TianXing <gztxwang AT public1 DOT guangzhou DOT gd DOT cn>
Organization: No Organization
MIME-Version: 1.0
To: Kenneth Foo <kenfoo AT techm DOT pl DOT my>
CC: djgpp AT delorie DOT com
Subject: Re: typedef struct inheritance -- not possible?
References: <828969663 DOT 273snx AT techm DOT pl DOT my>

Kenneth Foo wrote:
> 
> Why can't this work under DJGPP?
> It did work under Visual C++ and Turbo C++...
> 
> typedef struct {
>     int one;
>     } BASE;
> 
> typedef struct : BASE {
>     int two;
>     } DERIVED;
> 
> Is this valid under ANSI C (c++?) ?

It's definitely ill-formed under ANSI C.  But I can't find any
wording in the draft C++ standard that prohibits this.  So, VC++
and TC++ may be doing the right thing.

Anyway, your problem is easy to solve:

struct BASE {
    int one;
    };

struct DERIVED : BASE {
    int two;
    };

You can even your definition of BASE, but it's a bit stranger.

> What I'm trying to do is to derive a class called DERIVED from BASE.
> Hopefully, this avoids those silly constructors during creation.
> 

I don't know what silly constructors you are avoiding.


Regards,
Wang TianXing

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019