473,698 Members | 2,024 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 3033
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
5000
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
11378
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
10340
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
3510
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
3601
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
4101
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
9995
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
7519
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
6015
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
8674
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
8603
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
9023
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
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...
0
7721
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
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...
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1999
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.