[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] arv og arrays



gnalle wrote:

> Følgende program ser ud til at compile, men når jeg ser i Bjarne
> Stroustrups bog, kan jeg ikke gennemskue hvorfor:
>
> class a {
>   double x;
> };
>
> class b:public a{
> };
>
> int main(int argc, char *argv[])
> { a *myarray;
>   myarray = new b[2];
> }
>
> Er det altid tilladt at gøre sådan. Det jeg leder efter er egentlig en
> litteraturhenvisning, så jeg kan benytte denne metode med ro i sjælen.
>

Hejsa!

Først undskyld det meget sene svar (post-problemer).

Din kode ovenfor oversætter nok fordi, at en "peger til a" gerne må pege
på et b-objekt, da b er en subklasse af a. Jeg tror nemlig ikke, at
oversætteren knytter anden type-info til din b-tabel end b.

Jeg mener dog helt klart, at du vil få problemer med denne konstruktion.
Nu er layoutet for a og b jo helt ens i  dit eksempel, men hvis det ikke
længere er tilfældet, så kan oversætteren vel ikke afgøre hvor myarray[1]
starter.....

Generelt har arv og arrays det ikke ret godt sammen.... Et godt eksempel
på dette er Javas type-regler for arrays...


Venlig hilsen
  Anders Nielsen





 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *