473,385 Members | 1,720 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,385 software developers and data experts.

Help with strange (for me) STL problem that disappers when rebuilding all

I have a class Bounds with two constructors:

class Bounds
{
private:

list<SegmentupperLinearSpline; // Upper bound.
list<SegmentlowerLinearSpline; // Lower bound.
....

}
Bounds::Bounds()
{
}

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 <listfile.

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

Apr 29 '07 #1
12 2240

StephQ <as*******@mailinator.comwrote in message ...
I have a class Bounds with two constructors:

class Bounds{ private:
list<SegmentupperLinearSpline; // Upper bound.
list<SegmentlowerLinearSpline; // Lower bound.
...
// }

};

Your problem is right here: You need a semicolon!
>
void _Insert(iterator _Where,
A leading underscore followed by a capital letter is reserved to the
implementation (so are double underscores), you should NOT use them.
>
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
If you have two files in your project, A.cpp and B.cpp, and B.cpp uses
something from A.cpp, and you change something in the interface in A.cpp,
you need to re-compile BOTH(all) files.
It's NOT a problem, it's how 'make/link' works (it only compiles files that
have changed since the last (full) compile).

--
Bob R
POVrookie
Apr 29 '07 #2
On Apr 29, 10:47 am, StephQ <askmeo...@mailinator.comwrote:
I have a class Bounds with two constructors:

class Bounds
{
private:

list<SegmentupperLinearSpline; // Upper bound.
list<SegmentlowerLinearSpline; // 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 <listfile.

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.
Apr 29 '07 #3
Salt_Peter skrev:
On Apr 29, 10:47 am, StephQ <askmeo...@mailinator.comwrote:
>I have a class Bounds with two constructors:

class Bounds
{
private:

list<SegmentupperLinearSpline; // Upper bound.
list<SegmentlowerLinearSpline; // Lower bound.
...

}

Bounds::Bounds()
{

}

Bounds::Bounds : upperLinearSpline(), lowerLinearSpline()
{
}
Unnecessary. They are initialized properly anyway, you don't
need to call the default constructor explicitly.

--
OU

Apr 29 '07 #4
On Apr 29, 2:11 pm, Salt_Peter <pj_h...@yahoo.comwrote:
On Apr 29, 10:47 am, StephQ <askmeo...@mailinator.comwrote:
I have a class Bounds with two constructors:
class Bounds
{
private:
list<SegmentupperLinearSpline; // Upper bound.
list<SegmentlowerLinearSpline; // Lower bound.
...
}
Bounds::Bounds()
{
}

Bounds::Bounds : upperLinearSpline(), lowerLinearSpline()
typo:

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 <listfile.
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.

Apr 29 '07 #5
Salt_Peter wrote:
On Apr 29, 2:11 pm, Salt_Peter <pj_h...@yahoo.comwrote:
>On Apr 29, 10:47 am, StephQ <askmeo...@mailinator.comwrote:
>>I have a class Bounds with two constructors:
>>class Bounds
{
private:
>> list<SegmentupperLinearSpline; // Upper bound.
list<SegmentlowerLinearSpline; // Lower bound.
...
>>}
>>Bounds::Bounds()
{
>>}

Bounds::Bounds : upperLinearSpline(), lowerLinearSpline()

typo:

Bounds::Bounds() : upperLinearSpline(), lowerLinearSpline()
[..]
Since both 'Spline' things are standard list containers, there is
no need to initialise them explicitly, the default initialisation
should work just fine.
>>
Always initialize all your members, thats not the compiler's job -
its yours. You've not shown enough code to detect any other issues.
You've not detected any issues. Neither have I, but I didn't look.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 29 '07 #6
On Apr 29, 8:06 pm, "BobR" <removeBadB...@worldnet.att.netwrote:
StephQ <askmeo...@mailinator.comwrote in message ...
I have a class Bounds with two constructors:
class Bounds{ private:
list<SegmentupperLinearSpline; // Upper bound.
list<SegmentlowerLinearSpline; // Lower bound.
...

// }

};

Your problem is right here: You need a semicolon!
Sorry, I made a mistake in pasting only this part of the class. This
error is not present in the complete version of the code.
void _Insert(iterator _Where,

A leading underscore followed by a capital letter is reserved to the
implementation (so are double underscores), you should NOT use them.
The part pasted is from the STL that shipped with my compiler (visual
studio 2005). I posted it just in case someone weally expert with STL
could deduce what could be wrong with my code.
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

If you have two files in your project, A.cpp and B.cpp, and B.cpp uses
something from A.cpp, and you change something in the interface in A.cpp,
you need to re-compile BOTH(all) files.
That's the point. The strange point is that in this case if I don't
recompile everything I get problems with my constructor. And the
problem appears in the function I reported. But I'm almost sure that
it's a problem of my software, and not of the STL implementation,
which should have been tested a lot more than my code.

Cheers
StephQ
Apr 29 '07 #7
On Apr 29, 10:06 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Salt_Peter wrote:
On Apr 29, 2:11 pm, Salt_Peter <pj_h...@yahoo.comwrote:
On Apr 29, 10:47 am, StephQ <askmeo...@mailinator.comwrote:
>I have a class Bounds with two constructors:
>class Bounds
{
private:
> list<SegmentupperLinearSpline; // Upper bound.
list<SegmentlowerLinearSpline; // Lower bound.
...
>}
>Bounds::Bounds()
{
>}
Bounds::Bounds : upperLinearSpline(), lowerLinearSpline()
typo:
Bounds::Bounds() : upperLinearSpline(), lowerLinearSpline()
[..]

Since both 'Spline' things are standard list containers, there is
no need to initialise them explicitly, the default initialisation
should work just fine.
Always initialize all your members, thats not the compiler's job -
its yours. You've not shown enough code to detect any other issues.

You've not detected any issues. Neither have I, but I didn't look.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I will try the explicit initialization suggestion with the default
constructor to see if it makes a difference.
Is explicitely calling the default constructor necessary in same
situations?
Cheers
StephQ

Apr 29 '07 #8

StephQ wrote in message ...
On Apr 29, 8:06 pm, "BobR" wrote:
class Bounds{ private:
list<SegmentupperLinearSpline; // Upper bound.
list<SegmentlowerLinearSpline; // Lower bound.
...
};
void _Insert(iterator _Where,
[snip]
The part pasted is from the STL that shipped with my compiler (visual
studio 2005).
Oh. The upper-case ' I ' fooled me. I've only seen implementations that use
all lower-case in the public interface of the STL:

// from stl_list.h (#included thru <list>, GCC)
iterator insert(iterator __position, const value_type& __x);
If you have two files in your project, A.cpp and B.cpp, and B.cpp uses
something from A.cpp, and you change something in the interface in
A.cpp,
you need to re-compile BOTH(all) files.

That's the point. The strange point is that in this case if I don't
recompile everything I get problems with my constructor. And the
problem appears in the function I reported. But I'm almost sure that
it's a problem of my software, and not of the STL implementation,
which should have been tested a lot more than my code.
Cheers, StephQ
You'll need to post more code to get help. Reduce your code to the smallest
that will exhibit the problem, and post that (if the solution didn't jump
out at you in the process). We'll need to see class Bounds, class Segment,
and the part in main(or?) where you use the class[es] (esp. the
list.insert()).

--
Bob R
POVrookie
Apr 30 '07 #9
StephQ wrote:
[..]
I will try the explicit initialization suggestion with the default
constructor to see if it makes a difference.
Trust me, it won't make any.
Is explicitely calling the default constructor necessary in same
situations?
Only in case of POD. For classes that have their own constructors
(either user-defined, or compiler-provided) there's no difference.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 30 '07 #10
"StephQ" <as*******@mailinator.comwrote in message
news:11*********************@e65g2000hsc.googlegro ups.com...
>I have a class Bounds with two constructors:

class Bounds
{
private:

list<SegmentupperLinearSpline; // Upper bound.
list<SegmentlowerLinearSpline; // Lower bound.
...

}
Bounds::Bounds()
{
}

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, .......


You have some class that accepts a constant reference to an instance of
Bounds. Well, you haven't shown any code where the constructor would be
called. Why don't you try posting a complete compilable program that shows
the issue? We're only getting bits and pieces here.
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 <listfile.

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

Apr 30 '07 #11
On Apr 29, 4:47 pm, StephQ <askmeo...@mailinator.comwrote:
I have a class Bounds with two constructors:
class Bounds
{
private:

list<SegmentupperLinearSpline; // Upper bound.
list<SegmentlowerLinearSpline; // Lower bound.
...
}
Bounds::Bounds()
{
}
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.
Practically, there are two things which can cause this: a header
file has been modified since the last full build, but one of the
source files which reused it was not recompiled, or you used
different options in the earlier compilations. (Note that even
such basic things as sizeof( std::list<Something) may change
depending on compiler options.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Apr 30 '07 #12
Sorry about that. I will post a reproducible example as soon as
possible.
Probably after Wednsday becouse I have to finish some parts of the
software before that date.

Cheers
StephQ
Apr 30 '07 #13

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

Similar topics

3
by: Mitchell Thomas | last post by:
I hope someone out there can solve my mysterious problem. I have tried everything imaginable, even paid $35 to Microsoft to help me, but they were not able to figure out this problem: Here is the...
3
by: Jacek Jurkowski | last post by:
My app worked fine in VS.net 2005 B1 and B2 some time ... Now (B2) when I'm trying to design some windows in my application (not all) i'm getting bug showed bellow but I DO NOT have SizeF property...
3
by: Don | last post by:
Hi: Anything I can change in VS.NET or IIS to get changes from and XSL stylesheet to show immediately without rebuilding? I have an ASP.NET application to with one page that renders XML/XSLT....
28
by: Siv | last post by:
Hi, If I run the following: strSQL = "Select * FROM Clients;" da = New OleDb.OleDbDataAdapter(strSQL, Conn) 'Create data adapter cb = New OleDb.OleDbCommandBuilder(da) ...
3
by: Simon Harvey | last post by:
Hi everyone, I keep getting a problem with dropdownlist controls. It sounds really stupid, but my app is screwed as long as this keeps happening. It seems to spontaneously happen and then I...
2
by: 4MLA1FN | last post by:
i'm building a little web app for my research project. url is here: http://www.cognitivecomposites.com/wtf/ it validates as xhtml/strict according to: ...
85
by: abhi | last post by:
hi everybody am new to this group and help me to learn C
1
by: manontheedge | last post by:
i'm using microsoft visual studio 6.0, and i have a program that reads in a text file, then looks for a variety of things, sorts them into categories, and prints them out ( to the console AND a...
6
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
Yesterday Visual Studio gave me a strange error both at compiletime and at designtime that had no obvious connection to anything I had changed recently. After some effort tracking down the problem...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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.