www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/06/19:00:09

From: "Tim \"Zastai\" Van Holder" <zastai AT hotmail DOT com>
Newsgroups: comp.os.msdos.djgpp
References: <8i5mum$4nv$1 AT nnrp1 DOT deja DOT com>
Subject: Re: class inheritance problems
Lines: 80
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2314.1300
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Message-ID: <9Y795.15558$Ud2.253895@afrodite.telenet-ops.be>
Date: Thu, 06 Jul 2000 22:43:17 GMT
NNTP-Posting-Host: 213.224.63.5
X-Trace: afrodite.telenet-ops.be 962923397 213.224.63.5 (Fri, 07 Jul 2000 00:43:17 MET DST)
NNTP-Posting-Date: Fri, 07 Jul 2000 00:43:17 MET DST
Organization: Pandora - Met vlotte tred op Internet
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

<highlander88 AT my-deja DOT com> wrote in message
news:8i5mum$4nv$1 AT nnrp1 DOT deja DOT com...
> I have several burning questions and plead for anyones assistance.
> [snip]
> 1. dynamic array of pointers to objects
>
> I am trying to alloate array of pointers to window and assign it to
> children, but get incompatible types in assignment of window** to
> 'window*[0]'
> if I define childeren as 'window **children' I get:
> 'syntax error before '*' on the line childern = new *window[256];
First of all, you could make your life a little easier by using the STL;
this gets rid of many troublesome pointers.
String variables could be STL strings and your children could/should be a
deque<window*> (or possibly a list<window*>, depending on what you need to
do to the list.
Secondly, 'new *foo[x]' is illegal code; to allocate an array of pointers,
you
need 'new foo*[x]': the syntax is 'new type[array-size]', and here
'window*',
not '*window', is the type.

> 2. My second problem is having an array of windows in another unrelated
> class:
>
> class win_mgr  //: public window //originaly to be base class
> {
>
> public:
>     win_mgr( );
>     win_mgr( int table_size );
>     ~win_mgr();
>
>     window      *window_list;
>
> private:
>     int         list_size;
>     int         list_items;
> };
>
> win_mgr::win_mgr( void )
> //window( (char *) NULL,  0, -1, 0, 0, 0,  file://originaly intended
to be a
> //       (rect *)NULL, (MENU *)NULL, 0 )   file://base class
Again, when in C++, don't act C: use 0 instead of NULL (and certainly
without casts).

> [snip]
>
> I get a syntax error before '*' (in the declaration:
> window *window_list;
> in the inlude file eventhogh I have declared win_mgr to be a friend in
> the window class.
The 'friend' has nothing to do with it; it merely tells the compiler to
allow win_mgr
access to window's private members. Why is it there though? Aside from the
fact that
'friend' should be avoided, it seems useless here: neither window nor the
classes it's derived
from has any private members...
The actual problem is fairly silly and I personally think the compiler
should have generated
a more helpful message. You use 'conio.h', and that contains a 'window'
function. So the
compiler sees a function were a type was expected. You may get away with
using 'class window',
but you should either call the class something else, or, preferably, put all
your stuff in a namespace
to avoid naming conflicts.

--
Hi, I'm a signature virus. plz set me as your signature and help me spread
:)






- Raw text -


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