小编Aha*_*han的帖子

为什么这段代码会导致无限循环

unsigned int i = 1<<10;

for(; i>=0; i--) printf(“%d\n”, i);
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释为什么这个代码导致无限循环?提前感谢您的回复.

c

4
推荐指数
1
解决办法
153
查看次数

使用shared_ptr C++双重删除错误

我有以下课程设计:

struct compare{
template <typename T>
bool operator()(const T& a, const T&b){ return *a < *b;}
};

class Trans;

typedef set<shared_ptr<Trans>, compare > TransPointerSet;

class Place{

  // other data members
 TransPointerSet nextTrans;

public:

  // constructor and other methods including overloaded < operator
  void insertNextTrans(shared_ptr<Trans> t){ nextTrans.insert(t); }
  void removeNextTrans() { nextTrans.clear(); }

};

typedef set<shared_ptr<Place>, compare > PlacePointerSet;

class Trans{

//other data members
PlacePointerSet inPlaces;
PlacePointerSet outPlaces;

public:

//constructor and others including overloaded < operator
void insertInPlace(shared_ptr<Place> p){ 
     inPlaces.insert(p); 
     p->insertNextTrans(shared_ptr<Trans>(this)); …
Run Code Online (Sandbox Code Playgroud)

c++ stl shared-ptr

1
推荐指数
2
解决办法
1316
查看次数

标签 统计

c ×1

c++ ×1

shared-ptr ×1

stl ×1