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的主要内容,如果未能解决你的问题,请参考以下文章

C++助教篇8_操作符重载的前后置

C++助教篇7_继承的十种常见情况

C++助教篇5_Week3不完全知识点总结

Week4 案例分析

斯坦福-随机图模型-week4.2_

习题5_9 找bug(Bug Hunt, ACM/ICPC Tokyo 2007, UVa1596)