G****A 发帖数: 4160 | 1 // main.cpp
// 10005
#include
#include
using namespace std;
class Monitor {
int num;
public:
Monitor() { num = 1; }
// ~Monitor() {cout<<"des11"<
void incident() { num++; }
void decrement() { num--;}
void print() { cout<<"The times of incident :"<
}
};
class Monitor2 {
Monitor *m;
public:
Monitor2(Monitor * mm): m | t****t 发帖数: 6806 | 2 1.这个code写得不太好
2.你水平也确实不够,因为虽然写得不好,意图还是很明显的
3.提示: google shared_ptr,或者 reference counting
【在 G****A 的大作中提到】 : // main.cpp : // 10005 : #include : #include : using namespace std; : : class Monitor { : int num; : public: : Monitor() { num = 1; }
| r**u 发帖数: 130 | 3 if no static before monitor2, the result is:
The times of incident :2
the times of incident :1
main()
it's easy to understand, however, after put static, the result becomes:
The times of incident :2
main()
The times of incident :-1
seems strange, any explanation? Thx.
【在 G****A 的大作中提到】 : // main.cpp : // 10005 : #include : #include : using namespace std; : : class Monitor { : int num; : public: : Monitor() { num = 1; }
|
|