473,796 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Do my types meet container requirements?

Hello all,

In the code below, can anybody see that I am violating any of the rules that
types must abide by to be held in containers? I get a memory access problem
when a ZoneSetsType destructs...

Thanks,
Dave

struct OnePolygonType
{
unsigned int ModTime;
std::string Pts;
std::string Type;

unsigned int Id; // Unused in comparing objects

// Implement a strict weak ordering
bool operator<(const OnePolygonType &rhs) const
{
if (ModTime < rhs.ModTime)
return true;
else if (ModTime > rhs.ModTime)
return false;

if (Pts < rhs.Pts)
return true;
else if (Pts > rhs.Pts)
return false;

if (Type < rhs.Type)
return true;
else if (Type > rhs.Type)
return false;

return false;
}

bool operator==(cons t OnePolygonType &rhs) const
{
return (
(ModTime == rhs.ModTime) &&
(Pts == rhs.Pts) &&
(Type == rhs.Type)
);
}
};

typedef std::set<OnePol ygonType> PolygonSetType;

struct ZoneSetType
{
PolygonSetType SafeZones;
PolygonSetType HotZones;

// Implement a strict weak ordering
bool operator<(const ZoneSetType &rhs) const
{
if (SafeZones < rhs.SafeZones)
return true;
else if (SafeZones > rhs.SafeZones)
return false;

if (HotZones < rhs.HotZones)
return true;
else if (HotZones > rhs.HotZones)
return false;

return false;
}

bool operator==(cons t ZoneSetType &rhs) const
{
return (
(SafeZones == rhs.SafeZones) &&
(HotZones == rhs.HotZones)
);
}
};

typedef std::map<std::s tring, ZoneSetType> ZoneSetsType;
Jul 22 '05 #1
8 1262
Dave wrote:
Hello all,

In the code below, can anybody see that I am violating any of the rules that
types must abide by to be held in containers? I get a memory access problem
when a ZoneSetsType destructs...

Thanks,
Dave

[code snipped]

In the code you had shown you are not creating any instance of
ZoneSetsType anywhere (statically / dynamically ) .
Also your classes do not seem to have any pointers / files as its
members. (and hence the default copy ctor. / assignment operator /
destructor would be fine). So the problem does not seem to be with the
class definitions but with the client code of the class. Please post the
precise code that you were working on, to understand the problem better.

--
Karthik.
Jul 22 '05 #2

"Karthik Kumar" <ka************ *******@yahoo.c om> wrote in message
news:41c8aaea$1 @darkstar...
Dave wrote:
Hello all,

In the code below, can anybody see that I am violating any of the rules that types must abide by to be held in containers? I get a memory access problem when a ZoneSetsType destructs...

Thanks,
Dave

[code snipped]

In the code you had shown you are not creating any instance of
ZoneSetsType anywhere (statically / dynamically ) .
Also your classes do not seem to have any pointers / files as its
members. (and hence the default copy ctor. / assignment operator /
destructor would be fine). So the problem does not seem to be with the
class definitions but with the client code of the class. Please post the
precise code that you were working on, to understand the problem better.

--
Karthik.


This will be out of context, but here's what the client code is so far (I've
just started developing this function).
As you can see, I'm simply locally declaring and initializing an instance of
the problem type. When ZoneSetsFromMes sage goes out of scope and destructs
upon function exit, I get the memory access problem. Please note that this
happens even if I do not initialize ZoneSetsFromMes sage. Default
constructing it and letting it destruct naturally reproduces the problem.

I tried compiling the code from my original post on Comeau online and it
complained about some concept checks failing. For example:

"concept_checks .h", line 405: error: no operator "!=" matches these operands
operand types are: OnePolygonType != OnePolygonType
if (__a == __b || __a != __b) return __a;
^
detected during:
instantiation of "_Type

_STL_ERROR::__e quality_compara ble_requirement _violation(_
Type, _Type) [with _Type=OnePolygo nType]" at line 555
instantiation of "void
[error snipped]

There were 5 similar errors. I don't understand what C++ rule this is
telling me I'm violating.

Thanks,
Dave

Here's the client code:

void PsrsClient::Han dleUnitZones(co nst unsigned char *&p, size_t &s)
{
UnitZonesIbMess age0 Msg(p, s);
PolygonTransfer Vector_t Polygons = Msg.GetPolygons ();
ZoneSetsType ZoneSetsFromMes sage = CreateZoneSetsT ypeFromMessage( Polygons);

// assert(ZoneSets FromMessage.siz e() == 1);
// ZoneSetType ZoneSet = ZoneSetsFromMes sage.begin()->second;
}
Jul 22 '05 #3
"Dave" <be***********@ yahoo.com> wrote in
news:10******** *****@news.supe rnews.com:

[snippage]
"concept_checks .h", line 405: error: no operator "!=" matches these
operands
operand types are: OnePolygonType != OnePolygonType
if (__a == __b || __a != __b) return __a;
^
detected during:
instantiation of "_Type
OK... what part of this error message is bad? It's telling you that it
can't find an operator!= that matches the parameters that you're using with
it. Note that in the code you provided earlier I don't see you providing
an operator!=() anywhere.... (I _do_ see an operator==(), but that's a
whole different story....)

_STL_ERROR::__e quality_compara ble_requirement _violation(_
Type, _Type) [with _Type=OnePolygo nType]" at
line 555
instantiation of "void
[error snipped]


Umm... line 555 of what?

Jul 22 '05 #4

"Andre Kostur" <nn******@kostu r.net> wrote in message
news:Xn******** *************** ********@207.35 .177.135...
"Dave" <be***********@ yahoo.com> wrote in
news:10******** *****@news.supe rnews.com:

[snippage]
"concept_checks .h", line 405: error: no operator "!=" matches these
operands
operand types are: OnePolygonType != OnePolygonType
if (__a == __b || __a != __b) return __a;
^
detected during:
instantiation of "_Type
OK... what part of this error message is bad? It's telling you that it
can't find an operator!= that matches the parameters that you're using

with it. Note that in the code you provided earlier I don't see you providing
an operator!=() anywhere.... (I _do_ see an operator==(), but that's a
whole different story....)

Indeed, but nor do I ever use operator!= (my code *does* compile) and nor is
it a requirement of a type storable in an STL container!

_STL_ERROR::__e quality_compara ble_requirement _violation(_
Type, _Type) [with _Type=OnePolygo nType]" at
line 555
instantiation of "void
[error snipped]


Umm... line 555 of what?

Jul 22 '05 #5
Dave wrote:

This will be out of context, but here's what the client code is so far (I've
just started developing this function).
As you can see, I'm simply locally declaring and initializing an instance of
the problem type. When ZoneSetsFromMes sage goes out of scope and destructs
upon function exit, I get the memory access problem. Please note that this
happens even if I do not initialize ZoneSetsFromMes sage. Default
constructing it and letting it destruct naturally reproduces the problem.

I tried compiling the code from my original post on Comeau online and it
complained about some concept checks failing. For example:

"concept_checks .h", line 405: error: no operator "!=" matches these operands
operand types are: OnePolygonType != OnePolygonType
if (__a == __b || __a != __b) return __a;
^
detected during:
instantiation of "_Type

_STL_ERROR::__e quality_compara ble_requirement _violation(_
Type, _Type) [with _Type=OnePolygo nType]" at line 555
instantiation of "void
[error snipped]

There were 5 similar errors. I don't understand what C++ rule this is
telling me I'm violating.

Thanks,
Dave

Here's the client code:

void PsrsClient::Han dleUnitZones(co nst unsigned char *&p, size_t &s)
{
UnitZonesIbMess age0 Msg(p, s);
PolygonTransfer Vector_t Polygons = Msg.GetPolygons ();
ZoneSetsType ZoneSetsFromMes sage = CreateZoneSetsT ypeFromMessage( Polygons);

// assert(ZoneSets FromMessage.siz e() == 1);
// ZoneSetType ZoneSet = ZoneSetsFromMes sage.begin()->second;
}


There apppears to be two more objects in the local function.
Are you sure it is the ZoneSetsType that is causing the problem
and not the other objects when go out of scope, (say, Msg of type
UnitZonesIbMess age0 ).

--
Karthik.
Jul 22 '05 #6

"Karthik Kumar" <ka************ *******@yahoo.c om> wrote in message
news:41c8bf81$1 @darkstar...
Dave wrote:

This will be out of context, but here's what the client code is so far (I've just started developing this function).
As you can see, I'm simply locally declaring and initializing an instance of the problem type. When ZoneSetsFromMes sage goes out of scope and destructs upon function exit, I get the memory access problem. Please note that this happens even if I do not initialize ZoneSetsFromMes sage. Default
constructing it and letting it destruct naturally reproduces the problem.
I tried compiling the code from my original post on Comeau online and it
complained about some concept checks failing. For example:

"concept_checks .h", line 405: error: no operator "!=" matches these operands operand types are: OnePolygonType != OnePolygonType
if (__a == __b || __a != __b) return __a;
^
detected during:
instantiation of "_Type

_STL_ERROR::__e quality_compara ble_requirement _violation(_
Type, _Type) [with _Type=OnePolygo nType]" at line 555 instantiation of "void
[error snipped]

There were 5 similar errors. I don't understand what C++ rule this is
telling me I'm violating.

Thanks,
Dave

Here's the client code:

void PsrsClient::Han dleUnitZones(co nst unsigned char *&p, size_t &s)
{
UnitZonesIbMess age0 Msg(p, s);
PolygonTransfer Vector_t Polygons = Msg.GetPolygons ();
ZoneSetsType ZoneSetsFromMes sage = CreateZoneSetsT ypeFromMessage( Polygons);
// assert(ZoneSets FromMessage.siz e() == 1);
// ZoneSetType ZoneSet = ZoneSetsFromMes sage.begin()->second;
}


There apppears to be two more objects in the local function.
Are you sure it is the ZoneSetsType that is causing the problem
and not the other objects when go out of scope, (say, Msg of type
UnitZonesIbMess age0 ).

--
Karthik.


Actually, I believe I've now found out where the problem lies.

It's a VC++ 6.0 thing. The call to CreateZoneSetsT ypeFromMessage( ) is
across a DLL boundary, and each DLL has its own heap in this environment.
So, memory is allocated in one heap and deallocated in another. Ouch!

I guess I'll have to terminate this thread now since we've gotten into a
particular implementation' s quirks...

Thanks for the help!

Dave
Jul 22 '05 #7
"Dave" <be***********@ yahoo.com> wrote in
news:10******** *****@news.supe rnews.com:

"Andre Kostur" <nn******@kostu r.net> wrote in message
news:Xn******** *************** ********@207.35 .177.135...
"Dave" <be***********@ yahoo.com> wrote in
news:10******** *****@news.supe rnews.com:

[snippage]
> "concept_checks .h", line 405: error: no operator "!=" matches these
> operands
> operand types are: OnePolygonType != OnePolygonType
> if (__a == __b || __a != __b) return __a;
> ^
> detected during:
> instantiation of "_Type


OK... what part of this error message is bad? It's telling you that
it can't find an operator!= that matches the parameters that you're
using

with
it. Note that in the code you provided earlier I don't see you
providing an operator!=() anywhere.... (I _do_ see an operator==(),
but that's a whole different story....)

Indeed, but nor do I ever use operator!= (my code *does* compile) and
nor is it a requirement of a type storable in an STL container!


Huh? What's this error message about line 405 of "concept_checks .h" ?

Jul 22 '05 #8
Dave wrote:
It's a VC++ 6.0 thing. The call to CreateZoneSetsT ypeFromMessage( ) is
across a DLL boundary, and each DLL has its own heap in this environment.
So, memory is allocated in one heap and deallocated in another.


Only if you build it that way.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #9

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

Similar topics

5
3925
by: Jeremy Cowles | last post by:
I have been reading a book that focuses on understanding the intrinsic types of C++ in depth. The author's mentality is this: "Understand the intrinsic types, then learn the std types as needed later", but I have been reading the stroustrup (spelling?) book and he says that it is much better to learn the standard library first as a beginner, and then worry about the intrinsic types afterwards. So there is no doubt that you need to have a...
2
1310
by: bartek | last post by:
Hello, It is not possible to assign values to, say, a vector<float> due to the fact that arrays are not assignable. Theoretically there's a simple workaround which involves wrapping the array in a struct, e.g. struct float3 { float m;
8
1803
by: Kyle Kolander | last post by:
Sorry, I sent this to comp.std.c++ and meant to send it here as well... Why are the minimum size guarantees for fundamental types intentionally omitted from section 3.9.1 Fundamental types of the C++ standard? If indeed these guarantees can be inferred from other parts of the standard, and it is the intent of the standards committee that these guarantees exist, then why are they not listed in the most relevant section? I've been...
20
2648
by: pinkfloydhomer | last post by:
Is it well-defined and portable to do something like: typedef struct { int type; char c; } S1; typedef struct {
159
6349
by: Bob Timpkinson | last post by:
Hi, I have a 32-bit machine... Is there anyway I can get gcc to use the following integer sizes? char: 8 bits short: 16 bits int: 32 bits long: 64 bits long long: 128 bits
15
3538
by: Juha Nieminen | last post by:
I'm sure this is not a new idea, but I have never heard about it before. I'm wondering if this could work: Assume that you have a common base class and a bunch of classes derived from it, and you want to make a deque which can contain any objects of any of those types. Normally what you would have to do is to make a deque or vector of pointers of the base class type and then allocate each object dynamically with 'new' and store the...
30
4303
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
Let's say we had a simple function for returning the amount of days in a month: unsigned DaysInMonth(unsigned const month) { switch (month) { case 8: case 3: case 5:
50
4519
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): //------------------------------------------------------------------ template<typename Data_t> class SmartPointer { Data_t* data; void(*deleterFunc)(Data_t*);
55
3999
by: tonytech08 | last post by:
How valuable is it that class objects behave like built-in types? I appears that the whole "constructor doesn't return a value because they are called by the compiler" thing is to enable built-in-like behavior for objects of class type. That leads to the "necessity" for the exception machinery so that errors from constructors can be handled. Is all that complexity worth it just to get built-in-like behavior from class objects? Maybe a...
0
9533
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
10239
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
10190
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
9057
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
7555
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
6796
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
5447
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...
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.