C++助教篇9_Week4找bugs

Posted xioacd99

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++助教篇9_Week4找bugs相关的知识,希望对你有一定的参考价值。

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

以上是关于C++助教篇9_Week4找bugs的主要内容,如果未能解决你的问题,请参考以下文章