帮助奇怪的(对我来说)STL问题,重建所有时消失 [英] Help with strange (for me) STL problem that disappers when rebuilding all

查看:63
本文介绍了帮助奇怪的(对我来说)STL问题,重建所有时消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个构造函数的类Bounds:


class Bounds

{

private:


list< SegmentupperLinearSpline; //上限。

list< SegmentlowerLinearSpline; //下限。

....


}

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));

}

段是具有默认构造函数的另一个类。

我没有定义析构函数,复制构造函数和复制赋值。

所以应该使用自动的元文件。


class Bounds出现在construtors的其他类中,或/和

作为参考成员数据,如

.....

private:

const Bounds&边界;

....


直到这里一切正常。


现在我写代码另一个类,其中Bounds只出现在

构造函数中(而非成员数据),如:

UniformEnvelope :: UniformEnvelope(const Bounds& bounds,..... ..


,当我添加这个新类的源代码和头文件

并正常编译构造函数时,会发生什么? b $ b Bounds :: Bounds(double lo,double up)停止工作。

在调试模式下,我没有得到任何错误/异常,但我注意到了

push_back ()没有正常工作。它没有报告任何错误,但如果根本没有插入值,则不会报告



如果有任何帮助,请查看

函数未能插入的标准模板库(不返回错误/异常但是在

之后调用(* this)我看到:"(error)0" ;作为使用

调试器的唯一元素) _Incsize(1)in:


void _Insert(iterator _Where,

const _Ty& _Val)

{//在_Where插入_Val


#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;

}

< listfile中的



非常奇怪的事情(至少对我来说)是重新编译整个

项目解决了这个问题。

Do你知道问题可能是什么,我怎么能检查呢?


谢谢

StephQ

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

推荐答案



StephQ< as ******* @ mailinator.comwrote in message .. 。

StephQ <as*******@mailinator.comwrote in message ...

我有一个带有两个构造函数的类Bounds:


class Bounds {private:

list< SegmentupperLinearSpline; //上限。

list< SegmentlowerLinearSpline; //下限。

...
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 (迭代器_Where,
>
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.


>

非常奇怪的事(至少对我来说)是重新编译整个

项目解决了这个问题。

你知道问题是什么吗?我怎么能用b $ b来检查它?

谢谢StephQ
>
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



如果项目中有两个文件,A.cpp和B.cpp,以及B.cpp使用

来自A.cpp,你在A.cpp的界面中改变了一些东西,

你需要重新编译BOTH(所有)文件。

它不是一个问题em,它是''make / link''的工作原理(它只编译自上次(完整)编译以来
已经改变的文件)。


-

Bob R

POVrookie

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


4月29日上午10:47,StephQ< askmeo ... @ mailinator.comwrote:
On Apr 29, 10:47 am, StephQ <askmeo...@mailinator.comwrote:

我有一个带有两个构造函数的类Bounds:


class Bounds

{

private:


list< SegmentupperLinearSpline; //上限。

list< SegmentlowerLinearSpline; //下限。

...


}


Bounds :: Bounds()

{


}
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()

{

}


与参数化的ctor相同...

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));


}


段是另一个具有默认构造函数的类。

我没有定义析构函数,复制构造函数和复制赋值。

所以应该使用自动的元文本。


类Bounds出现在作为参考会员数据的建筑师中的其他课程为/和

,如

....

私人:

const Bounds&界限;

...


直到这里一切正常。


现在我为另一个人编写代码其中Bounds只出现在

构造函数中的类(不作为成员数据)如:

UniformEnvelope :: UniformEnvelope(const Bounds& bounds,...... 。


以及当我添加源代码和头文件
这个新类的
并正常编译构造函数时发生的事情

Bounds :: Bounds(double lo,double up)停止工作。

在调试模式下,我没有得到任何错误/异常,但我注意到

push_back( )没有正常工作。它不会报告任何错误,但如果根本没有插入值,则不会报告



如果有任何帮助,请查看标准模板库

函数未能插入(不返回错误/异常但是在

之后调用(* this)我看到:"(error)0"作为使用

调试器的唯一元素是_Inc size(1)in:


void _Insert(iterator _Where,

const _Ty& _Val)

{//在_Where插入_Val


#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;

}

< listfile中的



非常奇怪的事情(至少对我来说)是重新编译整个

项目解决了这个问题。

Do你知道问题可能是什么,我怎么能检查它?


谢谢

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


Salt_Peter skrev:
Salt_Peter skrev:

4月29,上午10:47,StephQ< askmeo ... @ mailinator.comwrote:
On Apr 29, 10:47 am, StephQ <askmeo...@mailinator.comwrote:

>我有一个带有两个构造函数的类Bounds:

类别界限
{
私人:

列表< SegmentupperLinearSpline; //上限。
list< SegmentlowerLinearSpline; //下限。
...

}

Bounds :: Bounds()


}
>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()

{

}


Bounds::Bounds : upperLinearSpline(), lowerLinearSpline()
{
}



不必要。无论如何它们都是正确初始化的,你不需要明确地调用默认构造函数。


-

OU

Unnecessary. They are initialized properly anyway, you don''t
need to call the default constructor explicitly.

--
OU


这篇关于帮助奇怪的(对我来说)STL问题,重建所有时消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆