unsigned int i = 1<<10;
for(; i>=0; i--) printf(“%d\n”, i);
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释为什么这个代码导致无限循环?提前感谢您的回复.
我有以下课程设计:
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)