在下有个关于容器问题想请教大家!!

sopecj_seu 2007-08-16 08:16:20
CHaulm theHaulm1,theHaulm2;
vector<CHaulm>::iterator it1,it2;

for (i=0; i<NHC; i++)
{
for (int j=0; j<NLC; j++)
{
for (int k=0; k<NWC; k++)
{
if (DummyCell[i][j][k]>=2)
{
for (m=0; m<DummyCell[i][j][k]; m++)
{

R=(rand()%1000)/1000.0;
n=static_cast<int>(R*DummyCell[i][j][k])+1;
for (it1=m_HaulmArray.begin(); it1!=m_HaulmArray.end(); it1++)
{
if (i==theHaulm1.GSN[0] && j==theHaulm1.GSN[1] && k==theHaulm1.GSN[2] && m==theHaulm1.HSN)
{
cout<<"CollisionVerdict.\n";
theHaulm1=*it1;
for (it2=m_HaulmArray.begin();it2!=m_HaulmArray.end(); it2++)
{
if (i==theHaulm2.GSN[0] && j==theHaulm2.GSN[1] && k==theHaulm2.GSN[2] && n==theHaulm2.HSN)
{
theHaulm2=*it2;
Vx=theHaulm1.vx-theHaulm2.vx;
Vy=theHaulm1.vy-theHaulm2.vy;
Vz=theHaulm1.vz-theHaulm2.vz;
Um=sqrt(Vx*Vx+Vy*Vy+Vz*Vz);
Pr=Nsubstitute/(pow(Multiple,3)*nHeight*nLength*nWidth)*theHaulm1.l*(theHaulm1.d+theHaulm2.d)*Um*T;

if (R>n/static_cast<double>(DummyCell[i][j][k])-Pr && n!=m)
{

CHaulm& theHaulmRef1 = *it1;
CHaulm& theHaulmRef2 = *it2;
HaulmCollision::BodyCollision(theHaulmRef1,theHaulmRef2);
}
}
}
}
}
}
}
}
}
}
在下想知道为什么程序不能进入if (i==theHaulm1.GSN[0] && j==theHaulm1.GSN[1] && k==theHaulm1.GSN[2] && m==theHaulm1.HSN),问题出在哪?谢谢您的帮助!
...全文
174 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sopecj_seu 2007-08-17
  • 打赏
  • 举报
回复
就比方说,我的这种情况该如何改?
sopecj_seu 2007-08-17
  • 打赏
  • 举报
回复
能举个例子吗?我的e-mail:ya_green78@163.com,谢谢您的指教!
taodm 2007-08-17
  • 打赏
  • 举报
回复
抽出每一层循环封装成函数。
sopecj_seu 2007-08-17
  • 打赏
  • 举报
回复
___________
for (it1=m_HaulmArray.begin(); it1!=m_HaulmArray.end(); it1++)
那就是这个for的条件为false了,看看你的vector里有没有内容
_______________________________________________________
我已经检查过,容器里面有内容。

——————————————————————————————
10重嵌套?不出错可以算奇迹了。
建议你for、if、switch、while嵌套总数不要过3。

嵌套太恐怖了,以后维护你代码的人肯定遭殃。
——————————————————————————
都是条件语句,不嵌套怎么办呢?有什么更好的办法吗?
sopecj_seu 2007-08-17
  • 打赏
  • 举报
回复
//********************************************************************************************************************
//****************************************碰撞判断成员函数中第三层循环 ***********************************************
void CExperiment::ThirdCircle(int (&MarkCell)[3], int TopMark, CHaulm& FirstHaulmRef, double Randomicity,int SerialA, int SerialB)
{
double Vx=0,Vy=0,Vz=0,Um=0,Pr=0;
cout<<"ThirdCircle.\n";
vector<CHaulm>::iterator it;
for (it=m_HaulmArray.begin(); it!=m_HaulmArray.end(); it++)
{
CHaulm& SecondHaulmRef = *it;
if (MarkCell[0]==SecondHaulmRef.GSN[0] && MarkCell[1]==SecondHaulmRef.GSN[1] && MarkCell[2]==SecondHaulmRef.GSN[2] && SerialB==SecondHaulmRef.HSN)
{
Vx=FirstHaulmRef.vx-SecondHaulmRef.vx;
Vy=FirstHaulmRef.vy-SecondHaulmRef.vy;
Vz=FirstHaulmRef.vz-SecondHaulmRef.vz;
Um=sqrt(pow(Vx,2)+pow(Vy,2)+pow(Vz,2));
Pr=Nsubstitute/(pow(Multiple,3)*nHeight*nLength*nWidth)*FirstHaulmRef.l*(FirstHaulmRef.d+SecondHaulmRef.d)*Um*dt;

if (Randomicity>SerialB/static_cast<double>(TopMark)-Pr && SerialB!=SerialA)
{
HaulmCollision::BodyCollision(FirstHaulmRef,SecondHaulmRef);
}
}
}
}
//********************************************************************************************************************
//****************************************碰撞判断成员函数中第二层循环 ***********************************************
void CExperiment::SecondCircle(int (&MarkCell)[3], int TopMark)
{
double R=0;
int N=0;
vector<CHaulm>::iterator it;
for (int i=0; i<TopMark; i++)
{
for (it=m_HaulmArray.begin(); it!=m_HaulmArray.end(); it++)
{
CHaulm& FirstHaulmRef = *it;
if (MarkCell[0]==FirstHaulmRef.GSN[0] && MarkCell[1]==FirstHaulmRef.GSN[1] && MarkCell[2]==FirstHaulmRef.GSN[2] && i==FirstHaulmRef.HSN)
{
R=(rand()%1000)/1000.0;
N=static_cast<int>(R*TopMark)+1;
ThirdCircle(MarkCell, TopMark, FirstHaulmRef,R, i, N);
}
}
}
//cout<<"SecondCircle.\n";
}
//********************************************************************************************************************
//****************************************碰撞判断成员函数中第一层循环 ***********************************************
void CExperiment::FirstCircle()
{
int MarkCell[3]={0,0,0};
for (int i=0; i<NHC; i++)
{
for (int j=0; j<NLC; j++)
{
for (int k=0; k<NWC; k++)
{
if (DummyCell[i][j][k]>=2)
{
MarkCell[0]=i;
MarkCell[1]=j;
MarkCell[2]=k;
SecondCircle(MarkCell,DummyCell[i][j][k]);
}
}
}
}
}
//********************************************************************************************************************
//***************************************************颗粒碰撞判断*****************************************************
void CExperiment::CollisionVerdict()
{
for (int i=0; i<NHC; i++)
{
for (int j=0; j<NLC; j++)
{
for (int k=0; k<NWC; k++)
{
if (DummyCell[i][j][k]>NumMax)
{
DummyCell[i][j][k]=NumMax;
}
}
}
}
//碰撞预测
FirstCircle();
}
程序改成这样了,但好象还是不行。
zsdhust 2007-08-16
  • 打赏
  • 举报
回复
嵌套太恐怖了,以后维护你代码的人肯定遭殃。
taodm 2007-08-16
  • 打赏
  • 举报
回复
10重嵌套?不出错可以算奇迹了。
建议你for、if、switch、while嵌套总数不要过3。
believefym 2007-08-16
  • 打赏
  • 举报
回复
for (it1=m_HaulmArray.begin(); it1!=m_HaulmArray.end(); it1++)
那就是这个for的条件为false了,看看你的vector里有没有内容

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧