473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

structure redefinition problem

I know the usually applied workaround for multiple definitions of
header files, but I have a problem on this one.

This time, I can't just ifndef the header file that defines my
structure.

So I have two classes that I've managed to dodge around this problem
for a while, but now I need the include in both classes. This wasn't
a problem until now, when I'm trying to declare an stl map with a
structure as a data type.

All I need is that structure, I don't need the rest of it. Is there a
way to extern a structure? Or do a forward declaration? I have the
include fine in the .c file, but now I want a member variable and I'm
not sure how to get it there.

Thanks,
~Scoots

Jul 3 '07 #1
6 3015
Scoots wrote:
I know the usually applied workaround for multiple definitions of
header files, but I have a problem on this one.

This time, I can't just ifndef the header file that defines my
structure.

So I have two classes that I've managed to dodge around this problem
for a while, but now I need the include in both classes. This wasn't
a problem until now, when I'm trying to declare an stl map with a
structure as a data type.

All I need is that structure, I don't need the rest of it. Is there a
way to extern a structure? Or do a forward declaration? I have the
include fine in the .c file, but now I want a member variable and I'm
not sure how to get it there.
Usually, if you need a map of your type, the type has to be completely
defined, a forward declaration just won't do.

I am sorry, I can't really grasp what you're saying about managing to
dodge stuff and knowing the usually applied work-around. Perhaps you
could just post a distilled version of your code...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 3 '07 #2
On Jul 3, 10:54 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Scoots wrote:
I know the usually applied workaround for multiple definitions of
header files, but I have a problem on this one.
This time, I can't just ifndef the header file that defines my
structure.
So I have two classes that I've managed to dodge around this problem
for a while, but now I need the include in both classes. This wasn't
a problem until now, when I'm trying to declare an stl map with a
structure as a data type.
All I need is that structure, I don't need the rest of it. Is there a
way to extern a structure? Or do a forward declaration? I have the
include fine in the .c file, but now I want a member variable and I'm
not sure how to get it there.

Usually, if you need a map of your type, the type has to be completely
defined, a forward declaration just won't do.

I am sorry, I can't really grasp what you're saying about managing to
dodge stuff and knowing the usually applied work-around. Perhaps you
could just post a distilled version of your code...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask- Hide quoted text -

- Show quoted text -
Yeah, sorry, I knew at the time it was vague but I couldn't find my
definition. Finally managed to dig it up, and it is not an anonymous
struct, fortunately. In researching this, I've found references that
you can't forward declare a typedef'ed anonymous struct, and while
this is typdef'ed, it isn't anonymous.

in filea.h (inside of a dll that is included through rt.h)
typedef struct _CBREQ /* cbr */
{
LONG cbIndex;
LONG cbOffset;
LONG cbType;
} CBREQ;
programwnd.h:
#include "rt.h" //no real way to move this to programwnd.cpp, same
dependencies I need in prgengine.h

class programwnd{

}

Prgengine.h:
#include <map>

class programwnd; //forward declaration for pointer to "owner"

class Prgengine{
private:
map<string,CBREQvariableMap
programwnd *m_masterWnd

}
in Prgengine.cpp:

#include "programwnd.h"
#include "Prgengine.h"


Jul 3 '07 #3
On Jul 3, 11:13 am, Scoots <bssalm...@traxcorp.comwrote:
On Jul 3, 10:54 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:


Scoots wrote:
I know the usually applied workaround for multiple definitions of
header files, but I have a problem on this one.
This time, I can't just ifndef the header file that defines my
structure.
So I have two classes that I've managed to dodge around this problem
for a while, but now I need the include in both classes. This wasn't
a problem until now, when I'm trying to declare an stl map with a
structure as a data type.
All I need is that structure, I don't need the rest of it. Is there a
way to extern a structure? Or do a forward declaration? I have the
include fine in the .c file, but now I want a member variable and I'm
not sure how to get it there.
Usually, if you need a map of your type, the type has to be completely
defined, a forward declaration just won't do.
I am sorry, I can't really grasp what you're saying about managing to
dodge stuff and knowing the usually applied work-around. Perhaps you
could just post a distilled version of your code...
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask- Hide quoted text -
- Show quoted text -

Yeah, sorry, I knew at the time it was vague but I couldn't find my
definition. Finally managed to dig it up, and it is not an anonymous
struct, fortunately. In researching this, I've found references that
you can't forward declare a typedef'ed anonymous struct, and while
this is typdef'ed, it isn't anonymous.

in filea.h (inside of a dll that is included through rt.h)
typedef struct _CBREQ /* cbr */
{
LONG cbIndex;
LONG cbOffset;
LONG cbType;

} CBREQ;

programwnd.h:
#include "rt.h" //no real way to move this to programwnd.cpp, same
dependencies I need in prgengine.h

class programwnd{

}

Prgengine.h:
#include <map>

class programwnd; //forward declaration for pointer to "owner"

class Prgengine{

private:
map<string,CBREQvariableMap
programwnd *m_masterWnd

}

in Prgengine.cpp:

#include "programwnd.h"
#include "Prgengine.h"- Hide quoted text -

- Show quoted text -
for debug purposes only I managed to get it to:

programwnd:
#include "prgengine.h"
prgengine.h:
#include "rtexec2.h"
class CProgramWnd;
class Prgengine{
private:
map<string,CBREQvariableMap;
programwnd *m_masterWnd ;
}

prgengine.cpp:
#include "PrgStackEngine.h"
#include "programwnd.h"
which removes the need for forward declaration through nested headers
(ick), but it works for debugging and getting this going.
and I get ~20 of about these error messages: Is that a problem?
c:\program files\microsoft visual studio\vc98\include\xtree(200) :
warning C4786: '?rbegin@?$_Tree@HU?$pair@$$CBHU_CBREQ@@@std@@U_Kf n@?
$map@HU_CBREQ@@U?$less@H@std@@V?$allocator@U_CBREQ @@@3@@2@U?
$less@H@2@V?$allocator@U_CBREQ@@@2@@std@@QAE?AV?$r ever
se_bidirectional_iterator@Viterator@?$_Tree@HU?$pa ir@$
$CBHU_CBREQ@@@std@@U_Kfn@?$map@HU_CBREQ@@U?$less@H @std@@V?
$allocator@U_CBREQ@@@3@@2@U?$less@H@2@V?$allocator @U_CBREQ@@@2@@std@@U?
$pair@$$CBHU_CBREQ@@@3@AAU43@PAU43@H@2@XZ' : identifier was trunca
ted to '255' characters in the browser information

Jul 3 '07 #4
for debug purposes only I managed to get it to:

programwnd:
#include "prgengine.h"
prgengine.h:
#include "rtexec2.h"
class CProgramWnd;
class Prgengine{
private:
map<string,CBREQvariableMap;
programwnd *m_masterWnd ;

}
prgengine.cpp:
#include "PrgStackEngine.h"
#include "programwnd.h"

which removes the need for forward declaration through nested headers
(ick), but it works for debugging and getting this going. So the
solution isn't urgent, for now I'll be able to continue coding, but I
would appreciate any insight you have in getting rid of this nested
header dependency.
and I get ~20 of about these error messages: but that's vs 6.0
specific.
c:\program files\microsoft visual studio\vc98\include\xtree(200) :
warning C4786: '?rbegin@?$_Tree@HU?$pair@$$CBHU_CBREQ@@@std@@U_Kf n@?
$map@HU_CBREQ@@U?$less@H@std@@V?$allocator@U_CBREQ @@@3@@2@U?
$less@H@2@V?$allocator@U_CBREQ@@@2@@std@@QAE?AV?$r ever
se_bidirectional_iterator@Viterator@?$_Tree@HU?$pa ir@$
$CBHU_CBREQ@@@std@@U_Kfn@?$map@HU_CBREQ@@U?$less@H @std@@V?
$allocator@U_CBREQ@@@3@@2@U?$less@H@2@V?
$allocator@U_CBREQ@@@2@@std@@U?
$pair@$$CBHU_CBREQ@@@3@AAU43@PAU43@H@2@XZ' : identifier was trunca
ted to '255' characters in the browser information

Jul 3 '07 #5
Scoots wrote:
for debug purposes only I managed to get it to:

programwnd:
#include "prgengine.h"
prgengine.h:
#include "rtexec2.h"
class CProgramWnd;
class Prgengine{
private:
map<string,CBREQvariableMap;
programwnd *m_masterWnd ;

}
prgengine.cpp:
#include "PrgStackEngine.h"
#include "programwnd.h"

which removes the need for forward declaration through nested headers
(ick), but it works for debugging and getting this going. So the
solution isn't urgent, for now I'll be able to continue coding, but I
would appreciate any insight you have in getting rid of this nested
header dependency.
and I get ~20 of about these error messages: but that's vs 6.0
specific.
Did you read them? They are not _error_ messages. They are *warnings*.
Ignore them.
c:\program files\microsoft visual studio\vc98\include\xtree(200) :
warning C4786: '?rbegin@?$_Tree@HU?$pair@$$CBHU_CBREQ@@@std@@U_Kf n@?
$map@HU_CBREQ@@U?$less@H@std@@V?$allocator@U_CBREQ @@@3@@2@U?
$less@H@2@V?$allocator@U_CBREQ@@@2@@std@@QAE?AV?$r ever
se_bidirectional_iterator@Viterator@?$_Tree@HU?$pa ir@$
$CBHU_CBREQ@@@std@@U_Kfn@?$map@HU_CBREQ@@U?$less@H @std@@V?
$allocator@U_CBREQ@@@3@@2@U?$less@H@2@V?
$allocator@U_CBREQ@@@2@@std@@U?
$pair@$$CBHU_CBREQ@@@3@AAU43@PAU43@H@2@XZ' : identifier was trunca
ted to '255' characters in the browser information
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 3 '07 #6
On 2007-07-03 17:13, Scoots wrote:
On Jul 3, 10:54 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>Scoots wrote:
I know the usually applied workaround for multiple definitions of
header files, but I have a problem on this one.
This time, I can't just ifndef the header file that defines my
structure.
So I have two classes that I've managed to dodge around this problem
for a while, but now I need the include in both classes. This wasn't
a problem until now, when I'm trying to declare an stl map with a
structure as a data type.
All I need is that structure, I don't need the rest of it. Is there a
way to extern a structure? Or do a forward declaration? I have the
include fine in the .c file, but now I want a member variable and I'm
not sure how to get it there.

Usually, if you need a map of your type, the type has to be completely
defined, a forward declaration just won't do.

I am sorry, I can't really grasp what you're saying about managing to
dodge stuff and knowing the usually applied work-around. Perhaps you
could just post a distilled version of your code...

Yeah, sorry, I knew at the time it was vague but I couldn't find my
definition. Finally managed to dig it up, and it is not an anonymous
struct, fortunately. In researching this, I've found references that
you can't forward declare a typedef'ed anonymous struct, and while
this is typdef'ed, it isn't anonymous.

in filea.h (inside of a dll that is included through rt.h)
typedef struct _CBREQ /* cbr */
{
LONG cbIndex;
LONG cbOffset;
LONG cbType;
} CBREQ;
Not related to your problem but unless you have to maintain
compatibility with C you don't need the typedef, just

struct CBREQ {
// ...
};

will do. And when I'm at it, all-caps identifiers are generally reserved
for macros.

--
Erik Wikström
Jul 3 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: lomat | last post by:
Hello, While compiling a file, I get following error .... ================================= /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/include/g++/type_traits.h:14 2: redefinition of...
10
by: tapeesh | last post by:
I created a C file say struct.c with the following structure declarations in the same file struct A { union key { int i; float f; }k1;
4
by: junaidnaseer | last post by:
Hi ! I am facing a problem that I have defined a function which when called in the same file generates an error as follows; " visual c error C2371 redefinition basic types see...
1
by: Alex | last post by:
Hello all, I have a very stupid problem that is driving me crazy...so plz if anyone ever saw this, I would like him to help me :) I have static MFC application in MSVC++ 6.0 (named Example)....
1
by: Martin.C.Johnsson | last post by:
Hi, I have the following problem The below class is fully defined in the header file thus there's no ..cpp-file. The header-file is included in several lib's I'm using. ---------- #pragma once...
3
by: DhaneshNair | last post by:
Hi all, I hav a file which is actually linkage file (used as an reference interface between c and c++ files). And this file has got two structures in it .. When i include this file directly i...
2
by: Mohammad Omer | last post by:
Hi, i am developing an application which uses WAB API's, for doing all this i am using vs2k5. I have wab.h header file included in my project to use WAB api's but after compilation one error...
9
by: pauldepstein | last post by:
On my visual c++ compiler, I compiled code which contained something like for( int i =0; i < 5; i++) { double x =5;} I expected it to give a compiler error because x is being redefined
4
by: sharat | last post by:
Hi all. I am writing a a code in c++ . i have defined a global structure in a header file(user define header file) say headerfile1.h and declared a class in file2.h which is having some public...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.