最近写代码不在状态,或者说从一开始就很少在状态。
首先码字准确不够,经常打错;
第二,打的不够快,尤其在符号上,比如 [ ] ( ) 0 ; \ / <> “”等
第三,心里想的,和手上打出来的不一致。
不知道是IDE不够智能,还是过于智能,但它不符合我的心意。
对代码无论从结构上、功能上一定要先组织好再动手 ,尽可能的一遍成功。
成员函数声明和实现分开,分别在h和cpp文件中
注意循环声明的情况,比如:
// code inside 'common.h'
class NIMBoard
{
private:
DLList<NIMBoard> m_Children; // line 22 (common.h)
....
....
};
// code inside 'dllist.h'
template<class T>
class DLList
{
private:
// Node class
class Node
{
public:
T Data; // line 21 (dllist.h)
....
....
};
....
....
};
再比如:
#include "stdafx.h"
class B;
class A
{
public:
B b; //..Giving error here
A()
{
printf("\nA()");
}
void print()
{
b.print();
printf("\nPrint in A");
}
~A()
{
delete b;
printf("\n~A()");
}
};
class B
{
public:
B()
{
printf("\nB()");
}
void print()
{
printf("\nPrint in B");
}
~B()
{
printf("\n~B()");
}
};
int _tmain(int argc, _TCHAR* argv[])
{
A a;
a.print();
return 0;
}
两个例子都是有问题的。