Board index » cppbuilder » Structures

Structures

This probably a stupid question but.

How do I declare an external structure.
ie I have defined a structure in one unit and need to access it in another.

struct talker { char talker_str[3];};
struct talker talkers[7] =
{{"11"},{"12"},{"13"},{"14"},{"15"},{"16"},{"17"},{"18"}};

How do I declare it in another unit?

 

Re:Structures


: "Trevor Macdonald" <tre...@pacmicro.com> wrote:

Quote
>I have defined a structure in one unit and need to access it in another.
...
>struct talker { char talker_str[3];};
...
>How do I declare it in another unit?

You move the

  struct talker { char talker_str[3];};

part to a header file and then #include this header file wherever you
would like to use the struct.

FWIW, this is rather a C++ language question than an IDE question.

--
Stefan Hoffmeister (TeamB)     http://www.econos.de/
Please do apply judgement when sending email.

Re:Structures


And remember that a struct is pretty much the same as a class, except it
has no Public, Private, Protected and so on.

J

--
.............
......... Jason C. Leach
...... University College of the Cariboo
... j...@mail.ocis.net
.. http://www.ocis.net/~jcl
.

The Search for Extraterrestrial Intelligence from Home:
http://setiathome.ssl.berkeley.edu

Re:Structures


Quote
Jason <j...@mail.ocis.net> wrote in message

news:37BD883A.35336830@mail.ocis.net...
Quote
> And remember that a struct is pretty much the same as a class, except it
> has no Public, Private, Protected and so on.

Well, actually it does. A class is private by default, and a struct is
public by default, but both allow the specification of private etc.

Liz

Re:Structures


Quote
>How do I declare an external structure.
>ie I have defined a structure in one unit and need to access it in another.

>struct talker { char talker_str[3];};
>struct talker talkers[7] =
>{{"11"},{"12"},{"13"},{"14"},{"15"},{"16"},{"17"},{"18"}};

>How do I declare it in another unit?

Declare in the unit header the struct and extern the array....

struct talker  { char talker_str[3];};
extern const struct talker talkers[];

this header may be included in any file needing to access the array.

add your initializer code to the cpp file...

const struct talker talkers[7] =
{{"11"},{"12"},{"13"},{"14"},{"15"},{"16"},{"17"},{"18"}};

Other Threads