struct & typedef

Started by
7 comments, last by Dante77 21 years, 1 month ago
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.
Dante77
Advertisement
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, 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.
Dante77
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.
Dante77
What you do, is this:

/*** Header File ***/
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 ***/
#include "HeaderFile.h"
//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 ***/
#include "HeaderFile.h"
//We can now use fe here, with no multiple declaration problems.
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 .
To Ready4Dis:

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

Dante77
Dante77
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 ---

Oh yeah, forgot.. your welcome.

[edited by - Ready4Dis on March 18, 2003 8:25:51 AM]
Yea, you''re right. Thats the way I like it. :-))
Dante77

This topic is closed to new replies.

Advertisement