编辑:这是关于下面介绍的(简化)案例中的最佳实践的讨论.无论您使用什么工具,编码风格或其他内容,都可以发布.谢谢.
为什么没有特殊方法来声明或定义ctors/dtors而不重复类的名称?这很烦人,特别是在原型设计和最终更改类的名称时.
我的意思是像这样的typedef:
struct SomeClassThatDoesSomething {
typedef SomeClassThatDoesSomething ThisClass;
ThisClass() { PrepareToDie(); }
ThisClass(int a) : _a(a) { PrepareToDie(); }
ThisClass(float a, int b) : _b(a), _a(b) { PrepareToDie(); }
ThisClass(float a, char * b) : _b(a), _c(b) { PrepareToDie(); }
ThisClass(char * a, int b) : _c(a), _a(b) { PrepareToDie(); }
ThisClass(ThisClass &rhs) { }
~ThisClass() {}
void Burn() {}
void PrepareToDie() {}
int _a;
float _b;
char *_c;
};
struct SomeDerivedClassThatDoesSomething : public SomeClassThatDoesSomething {
typedef …Run Code Online (Sandbox Code Playgroud)