switch中declare变量
switch (i){
case 1:
int val = 100;
break;
...
break;
}
答案:https://stackoverflow.com/questions/92396/why-cant-variables-be-declared-in-a-switch-statement
复制构造函数的多此一举
class TestClass{
TestClass(const TestClass &another){
if (pointer){
delete[] pointer;
pointer = nullptr;
}
pointer = new int [another.size];
}
private:
int *pointer;
int size;
};
答案:https://stackoverflow.com/questions/61632241/something-about-new-and-delete-in-c