delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/13/12:46:03

From: highlander88 AT my-deja DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: class inheritance problems
Date: Tue, 13 Jun 2000 16:19:38 GMT
Organization: Deja.com - Before you buy.
Lines: 427
Message-ID: <8i5mum$4nv$1@nnrp1.deja.com>
NNTP-Posting-Host: 64.56.226.117
X-Article-Creation-Date: Tue Jun 13 16:19:38 2000 GMT
X-Http-User-Agent: Mozilla/4.6 [en] (Win95; I)
X-Http-Proxy: 1.0 x58.deja.com:80 (Squid/1.1.22) for client 64.56.226.117
X-MyDeja-Info: XMYDJUIDhighlander88
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I have several burning questions and plead for anyones assistance.

I am trying to write a windowing application ( in text mode ) with
non-preemptively multitasked windows ( just plunging into it all).
But my C experience is realy making me hate C++.




1. dynamic array of pointers to objects

I have the following (in 'win_mgr.hh'):

class window:public rect
{
public:
friend class win_mgr;
    window( char *i_title, int i_style, int i_x, int i_y, int i_x_size,
           int i_y_size, window *i_parent, MENU *i_menu, int i_instance
);

char *title;
int  style;
int  x;
int  y;
int  x_size;
int  y_size;
rect *parent;
MENU *menu;
int  instance;


window *children[];
int list_size;
int list_items;

};

'win_mgr.c'

window::window( char *i_title, int i_style, int i_x, int i_y, int
i_x_size,
       int i_y_size, window *i_parent, MENU *i_menu, int i_instance )
{
    children = new *window[256];
    list_size = 256;
    list_items = 0;
    strcpy( title, i_title );
    style = i_style;
    x = i_x;
    y = i_y;
    x_size = i_x_size;
    y_size = i_y_size;
    parent = i_parent;
    menu = i_menu;
    instance = i_instance;
}

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];

*********
I am starting to think that it is imposible especily now that I remember
having similar difficulties with variable array of strings in 'C'. I was
 reating it inside a funtion that read the diretory and then trying to
pass it back so that the array may be copied into array in data segment.
*******

I have tried to declare children as rect* and then do
children = new rect[256];
this worked but for one I don't want to create 256 objects and
second (the novice I am )I am not sure how usefull the pointers to the
base class will be in acessing the window class functions.


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,  //originaly intended to be a
//       (rect *)NULL, (MENU *)NULL, 0 )   //base class
{

    list_size = 100;
    list_items = 0;
    window_list = new window;

}



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.


as they are right now I get:
win_mgr.hh(218) Error: syntax error before '*'
---------------------------------------------------------
here are the files 'win_mgr.hh'

// class win_manager must do some tasks that windows normaly does.  */
/* currently the thing I can think off is keeping list of all windows */
/* and dispatching key presses to the currently active window which */
/* in turn may pass it to its parent ( the DIALOG box ) if it does not
*/
/* process the key. The dialog box*/


#include "applib.h"
#include "conio.h"


class rect
{
public:
    int     left;
    int     top;
    int     right;
    int     bottom;
};


class sys_colors
{
public:
    sys_colors();
    long get_color( char* system_color )
    {
//     /* search color name in the list */

        return ( 1L );
    }


    struct
    {
        char *name;
        long color;
    } all_colors[150];

};


class window:public rect
{
public:
friend class win_mgr;
    window( char *i_title, int i_style, int i_x, int i_y, int i_x_size,
           int i_y_size, window *i_parent, MENU *i_menu, int i_instance
);
    window();
char *title;
int  style;
int  x;
int  y;
int  x_size;
int  y_size;
rect *parent;
MENU *menu;
int  instance;


rect *children;
//window *hildren;
int list_size;
int list_items;

};


class system
{
public:
friend class win_mgr;
    system();

    struct text_info orig_tx_info;
    struct text_info cur_tx_info;

};

class win_mgr  //: public window
{

public:
    win_mgr( );
    win_mgr( int table_size );

    ~win_mgr();

    window      *window_list;

private:
    int         list_size;
    int         list_items;


};



class button: public window
{
public:

int state;


button( char *title, int style, int x, int y, int x_size, int y_size,
       window *parent, MENU *menu, int instance );

void paint();

};


------------------
'win_mgr.cc'

#include "win_mgr.hh"
#define NULL 0

// this may in the future be the multitasking OS's job.
// for now this will save the entire screen under the application
// keep track of all 'popup'/'parent' windows and paste their contents
on
// the screen. Also dispathes messages to all windows (mouse and
keyboard)
// and provides other system services.
// all windows paint themselves into a buffer axactly the right size
// then the parent is responsible for pasting it into it's buffer and
passing
// it to it's parrent (grrrr).
// The system class may in the future be responsible for loading the
appropriate
// graphics library (text/graphics) depending on the current mode or
// requested mode (after the graphics mode has been set in response to
some
// command line parameter or application ini file .)


system::system()
{
    gettextinfo( &orig_tx_info );
    memcpy( &cur_tx_info, &orig_tx_info, sizeof orig_tx_info );
//    memcpy( &cur_tx_info, &orig_tx_info, size_of ( struct text_info )
);


}

win_mgr::win_mgr( int table_size )
//window( (char *) NULL,  0, -1, 0, 0, 0,
//       (window *)NULL, (MENU *)NULL, 0 )
{
    list_size = table_size;
//    window_list[0] = new (window*)[table_size];
//    window_list[0]= new window::window( NULL, 0,
//                               sys_environment->cur_tx_info.winleft,
//                               sys_environment->cur_tx_info.wintop,
//                               sys_environment->cur_tx_info.winright,
//                               sys_environment->cur_tx_info.winbottom,
//                               NULL, NULL, 0 );

    list_items = 1;
}


win_mgr::win_mgr( void )
//window( (char *) NULL,  0, -1, 0, 0, 0,
//       (rect *)NULL, (MENU *)NULL, 0 )
{

    list_size = 100;
    list_items = 0;
    window_list[0] = new window;

}


win_mgr::~win_mgr()
{
//    delete[] window_list;

//    window_list = (window**)0;
}



sys_colors::sys_colors()
{
    all_colors[0].name = "Desktop";
    all_colors[0].color = 0;
    all_colors[1].name= "Window";
    all_colors[1].color = 1;


}

//window::window()
//{
// return( NULL );
//}


window::window( char *i_title, int i_style, int i_x, int i_y, int
i_x_size,
       int i_y_size, window *i_parent, MENU *i_menu, int i_instance )
{
 rect *temp;
    children = new rect[256];
    list_size = 256;
    list_items = 0;
    strcpy( title, i_title );
    style = i_style;
    x = i_x;
    y = i_y;
    x_size = i_x_size;
    y_size = i_y_size;
    parent = i_parent;
    menu = i_menu;
    instance = i_instance;
}


button::button( char *title, int style, int x, int y, int x_size, int
y_size,
       window *parent, MENU *menu, int instance ):
window( title, style, x, y, x_size, y_size,
       parent, (MENU *)NULL, instance )
{
    state = 0;

}


-------------------
testapp.cc

#define COMPILE_GLOBALS     1

#include "key_def.h"
#include "applib.h"
//#include "conio.h"
#include "stdio.h"
#include "pc.h"
//#include "diskutil.h"
#include "win_mgr.hh"


#define  MAX_MENU_ITEMS  10


SUBMENU exit_items[] = { { "Exit", 3 ,0, 0, 1, 0, (void (*)())-1L },
                { "", 0, 0, 0, 0, 0, (void (*)())0L } };

SUBMENU no_items[] = { { "", 0, 0, 0, 0, 0, (void (*)())0L } };

MENU main_items[] = { { "Exit", 1, 0, 4, 1, 0, 0, (SUBMENU*)exit_items
},
              { "\0", 0, 0, 0, 0, 0, 0, ( SUBMENU*)no_items } };

extern int  menu_master_mode;
                                    /* want to be able to discard
changes.  */
char        title[] = "Temp Application";


int         orig_cursor;


system *sys_environment;
win_mgr *win_manager;
sys_colors *system_colors;


int  main( int, char *[] );



void main( int argc, char *argv[] )
{

    sys_environment = new system;
    win_manager = new win_mgr( );

    delete sys_environment;


}

void exit_func()
{

}


Great many thanks for any help or suggestions.
Cheers, Sam.


Sent via Deja.com http://www.deja.com/
Before you buy.

- Raw text -


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