TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Griffon Chan
from: Roy McNeill
date: 1995-08-18 23:37:06
subject: Problem in C++

GC> I'm facing a difficult problem in create and initialize an array of

 GC> structure in Borland C++ 4.0.





 GC> frame::frame()

 GC> {

 GC>   // Expression syntax error here!



 GC>   box={{'u',0x1F},{'r',0x1F},{'a',0x1F},{'t',0x1F},{'i',0x1F},{'o',0x1F},

 GC>        {'n',0x1F},{' ',0x19},{'ú',0x19},{' ',0x19},{'ú',0x19},{' ',0x19},

 GC>        {' ',0x19},{'G',0x17},{'r',0x17},{'i',0x17},{'f',0x17},{'f',0x17},

 GC>        {'o',0x17},{'n',0x17},{' ',0x17},{'º',0x19},{'È',0x10},{'Í',0x19}};

 GC> };



As far as I can tell, if you use this initialization syntax, you

have to do it in the same statement as the declaration of box[].

Since you can't do that inside the class declaration, you'll have

to use another syntax.



Try this (a smaller version, I'm *not* going to retype all of the

above mess ):



struct cell {char ch;unsigned int attr:8;};



class frame

{

  private:

    cell box[5];

  public:

    frame();

};



frame::frame()

{

  unsigned int j[5] = {1,2,3,4,5};

  char c[6] = {"abcde"}; // note 1 char bigger to allow for \0

  int i;

  for(i=0;i<5;i++)

  {

    box[i].ch   = j[i];

    box[i].attr = c[i];

  }

};



Cheers



--- PPoint 1.88


* Origin: Silicon Heaven (3:711/934.16)
SEEN-BY: 711/809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.