#### Archived

This topic is now archived and is closed to further replies.

# struct & typedef

## Recommended Posts

Hello, I''ve gto problem with struct''s & typedef''s in my work. It''s more ''bout C++ lang. I think. Problem is this: I''ve got this typedef: typedef struct { ...some stuf here (func. pointers...)... } funcexport_t; Then I have a bunch of source files. In one of theese files included header with previous stuff and: funcexport_t fe; But, when I need to acess this my-defined variable "fe" from another file, it says that it''s not declared and if I include header files or whatever with "fe", then its double defined symbol. What can I do with this? Please help. Thanx. Maybe I shouldn''t drink too much, it kills my brain. Dante.

##### Share on other sites
since your coding in C++ why not go the C++ way of declaring structs?

  struct funcexport_t{    //some variables and stuff};

make sure that the structure is available from the file that your trying to create an object of the struct in - one way is to place in a "main" header which all other .cpp files #include so that way you are guarenteed that the structure will be visible.

##### Share on other sites
Yeah, I also tried, but this is when it tells me that I declare symbol twice.

I just typedef "funcexport_t" in one shared file that is included in every .cpp, and then declare "funcexport_t fe" in another header, but that "fe" is acessible only from .cpp where header with "fe" was included. If I incude it anywhere else, it is "core_renderer.obj : error LNK2005: "struct funcexport_t fe" (?fe@@3Ufuncexport_t@@A) already defined in core_main.obj" or something like this.

##### Share on other sites
quote:
Original post by Spudder
since your coding in C++ why not go the C++ way of declaring structs?

    struct funcexport_t{    //some variables and stuff};

make sure that the structure is available from the file that your trying to create an object of the struct in - one way is to place in a "main" header which all other .cpp files #include so that way you are guarenteed that the structure will be visible.

Yeah, and sorry to say, this in next shit. I didn''t ask for some stupid answer ''bout how structure is written and "since your coding in C++ why not go the C++ way of declaring structs?". What does this mean? That typedef is just typedef of stuct. If i do this, it''s just struct, but OK. But this is totally out of hand.

##### Share on other sites
What you do, is this:

struct
{
...some stuf here (func. pointers...)...
} funcexport_t;

//This tells us the compiler that we have a varialbe fe declared somewhere externally
extern funcexport_t fe;

/*** Source File ***/
//This is our actual definition of the variable which all source files will use
funcexport_t fe;

/*** Another Source File That Wants to Use Fe ***/
//We can now use fe here, with no multiple declaration problems.

##### Share on other sites
By the way, the use of the typedef keyword in a struct is no longer required, it was required in C, but is not required in C++, so save yourself 8 keystrokes (keyword=7 + space) and omit that from your structs .

##### Share on other sites

Yeah, finally someone said the right thing. Thanx. And yes, it works fine. Thanx.

Dante77

##### Share on other sites
Heh, no problem. Just try not to get mad when someone posts something that doesn't help, at least he's trying, ya know . That, and if it wasn't for him, your post wouldn't have been on the most recent list, and I would never have clicked it .

--- Edit ---

[edited by - Ready4Dis on March 18, 2003 8:25:51 AM]

##### Share on other sites
Yea, you''re right. Thats the way I like it. :-))

• ### Forum Statistics

• Total Topics
628302
• Total Posts
2981922

• 10
• 11
• 11
• 10
• 10