473,387 Members | 1,573 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.

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==(const OnePolygonType &rhs) const
{
return (
(ModTime == rhs.ModTime) &&
(Pts == rhs.Pts) &&
(Type == rhs.Type)
);
}
};

typedef std::set<OnePolygonType> 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==(const ZoneSetType &rhs) const
{
return (
(SafeZones == rhs.SafeZones) &&
(HotZones == rhs.HotZones)
);
}
};

typedef std::map<std::string, ZoneSetType> ZoneSetsType;
Jul 22 '05 #1
8 1235
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.com> 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 ZoneSetsFromMessage 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 ZoneSetsFromMessage. 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::__equality_comparable_requirement_viol ation(_
Type, _Type) [with _Type=OnePolygonType]" 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::HandleUnitZones(const unsigned char *&p, size_t &s)
{
UnitZonesIbMessage0 Msg(p, s);
PolygonTransferVector_t Polygons = Msg.GetPolygons();
ZoneSetsType ZoneSetsFromMessage = CreateZoneSetsTypeFromMessage(Polygons);

// assert(ZoneSetsFromMessage.size() == 1);
// ZoneSetType ZoneSet = ZoneSetsFromMessage.begin()->second;
}
Jul 22 '05 #3
"Dave" <be***********@yahoo.com> wrote in
news:10*************@news.supernews.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::__equality_comparable_requirement_viol ation(_
Type, _Type) [with _Type=OnePolygonType]" at
line 555
instantiation of "void
[error snipped]


Umm... line 555 of what?

Jul 22 '05 #4

"Andre Kostur" <nn******@kostur.net> wrote in message
news:Xn*******************************@207.35.177. 135...
"Dave" <be***********@yahoo.com> wrote in
news:10*************@news.supernews.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::__equality_comparable_requirement_viol ation(_
Type, _Type) [with _Type=OnePolygonType]" 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 ZoneSetsFromMessage 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 ZoneSetsFromMessage. 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::__equality_comparable_requirement_viol ation(_
Type, _Type) [with _Type=OnePolygonType]" 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::HandleUnitZones(const unsigned char *&p, size_t &s)
{
UnitZonesIbMessage0 Msg(p, s);
PolygonTransferVector_t Polygons = Msg.GetPolygons();
ZoneSetsType ZoneSetsFromMessage = CreateZoneSetsTypeFromMessage(Polygons);

// assert(ZoneSetsFromMessage.size() == 1);
// ZoneSetType ZoneSet = ZoneSetsFromMessage.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
UnitZonesIbMessage0 ).

--
Karthik.
Jul 22 '05 #6

"Karthik Kumar" <ka*******************@yahoo.com> 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 ZoneSetsFromMessage 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 ZoneSetsFromMessage. 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::__equality_comparable_requirement_viol ation(_
Type, _Type) [with _Type=OnePolygonType]" 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::HandleUnitZones(const unsigned char *&p, size_t &s)
{
UnitZonesIbMessage0 Msg(p, s);
PolygonTransferVector_t Polygons = Msg.GetPolygons();
ZoneSetsType ZoneSetsFromMessage = CreateZoneSetsTypeFromMessage(Polygons);
// assert(ZoneSetsFromMessage.size() == 1);
// ZoneSetType ZoneSet = ZoneSetsFromMessage.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
UnitZonesIbMessage0 ).

--
Karthik.


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

It's a VC++ 6.0 thing. The call to CreateZoneSetsTypeFromMessage() 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.supernews.com:

"Andre Kostur" <nn******@kostur.net> wrote in message
news:Xn*******************************@207.35.177. 135...
"Dave" <be***********@yahoo.com> wrote in
news:10*************@news.supernews.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 CreateZoneSetsTypeFromMessage() 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
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...
2
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...
8
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...
20
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
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
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...
30
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
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): ...
55
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.