473,725 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3037
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...@com Acast.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,CBRE QvariableMap
programwnd *m_masterWnd

}
in Prgengine.cpp:

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


Jul 3 '07 #3
On Jul 3, 11:13 am, Scoots <bssalm...@trax corp.comwrote:
On Jul 3, 10:54 am, "Victor Bazarov" <v.Abaza...@com Acast.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,CBRE QvariableMap
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,CBRE QvariableMap;
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\inc lude\xtree(200) :
warning C4786: '?rbegin@?$_Tre e@HU?$pair@$$CB HU_CBREQ@@@std@ @U_Kfn@?
$map@HU_CBREQ@@ U?$less@H@std@@ V?$allocator@U_ CBREQ@@@3@@2@U?
$less@H@2@V?$al locator@U_CBREQ @@@2@@std@@QAE? AV?$rever
se_bidirectiona l_iterator@Vite rator@?$_Tree@H U?$pair@$
$CBHU_CBREQ@@@s td@@U_Kfn@?$map @HU_CBREQ@@U?$l ess@H@std@@V?
$allocator@U_CB REQ@@@3@@2@U?$l ess@H@2@V?$allo cator@U_CBREQ@@ @2@@std@@U?
$pair@$$CBHU_CB REQ@@@3@AAU43@P AU43@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,CBRE QvariableMap;
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\inc lude\xtree(200) :
warning C4786: '?rbegin@?$_Tre e@HU?$pair@$$CB HU_CBREQ@@@std@ @U_Kfn@?
$map@HU_CBREQ@@ U?$less@H@std@@ V?$allocator@U_ CBREQ@@@3@@2@U?
$less@H@2@V?$al locator@U_CBREQ @@@2@@std@@QAE? AV?$rever
se_bidirectiona l_iterator@Vite rator@?$_Tree@H U?$pair@$
$CBHU_CBREQ@@@s td@@U_Kfn@?$map @HU_CBREQ@@U?$l ess@H@std@@V?
$allocator@U_CB REQ@@@3@@2@U?$l ess@H@2@V?
$allocator@U_CB REQ@@@2@@std@@U ?
$pair@$$CBHU_CB REQ@@@3@AAU43@P AU43@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,CBRE QvariableMap;
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\inc lude\xtree(200) :
warning C4786: '?rbegin@?$_Tre e@HU?$pair@$$CB HU_CBREQ@@@std@ @U_Kfn@?
$map@HU_CBREQ@@ U?$less@H@std@@ V?$allocator@U_ CBREQ@@@3@@2@U?
$less@H@2@V?$al locator@U_CBREQ @@@2@@std@@QAE? AV?$rever
se_bidirectiona l_iterator@Vite rator@?$_Tree@H U?$pair@$
$CBHU_CBREQ@@@s td@@U_Kfn@?$map @HU_CBREQ@@U?$l ess@H@std@@V?
$allocator@U_CB REQ@@@3@@2@U?$l ess@H@2@V?
$allocator@U_CB REQ@@@2@@std@@U ?
$pair@$$CBHU_CB REQ@@@3@AAU43@P AU43@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...@com Acast.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
5006
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 `struct __type_traits<short int>' /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/include/g++/type_traits.h:10 2: previous definition here =================================
10
11380
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
10343
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 declaration of the function . " Could anyone please help me with this . Thank you
1
3515
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). That application is built by one company and its usage is to show functionality of their static libraries. Now I created dynamic link library CoreLibrary and I want to integrate it into this example. CoreLibrary worked properly with win32...
1
3605
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 class CCriticalSectionGuard ; class CCriticalSection
3
4104
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 dont have any issues. but according to some norms in the review I am not supposed to use this file direclty in the header file .. but its fine if i use that inside the corresponding file. To avoid compiler error, i forward declared the structure...
2
10002
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 comes like Error 1 error C2371: 'WCHAR' : redefinition; different basic types c: \program files\microsoft visual studio 8\vc\platformsdk\include \wabdefs.h 78
9
7523
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
6018
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 funtion which returns the struct variable and definition of the fun in in file1.cpp . I am getting the error in compilation that "struct_var' has incomplete type and not allowed and return type is incoplete. If i am trying to return the structure...
0
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.