由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 为什么我看不懂下面的code,是不是水平还不够?
相关主题
请教一道入门小题请教一个作用域的问题
大家来做题C++。compare double to float
题2[合集] C++问题(copy constructor)
a simple question for C++ class问一个简单的C++问题
请问一个exception题目一个指向指针的指针的引用?
两个继承问题问个char*的问题
C++疑问数组弱问
two c++ interview questions! (转载)[合集] 关于构造函数
相关话题的讨论汇总
话题: monitor话题: num话题: incident话题: monitor2话题: void
进入Programming版参与讨论
1 (共1页)
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; }

1 (共1页)
进入Programming版参与讨论
相关主题
[合集] 关于构造函数请问一个exception题目
C++菜问: 怎么这样也可以?两个继承问题
c++之极弱问C++疑问
请教一个c++ reference问题two c++ interview questions! (转载)
请教一道入门小题请教一个作用域的问题
大家来做题C++。compare double to float
题2[合集] C++问题(copy constructor)
a simple question for C++ class问一个简单的C++问题
相关话题的讨论汇总
话题: monitor话题: num话题: incident话题: monitor2话题: void