美文网首页
Visual Studio 2019的一个BUG

Visual Studio 2019的一个BUG

作者: fck_13 | 来源:发表于2020-04-28 22:29 被阅读0次
#include <iostream>

class B
{
public:
    B() {
        std::cout << "B" << std::endl;
    }

    ~B() {
        std::cout << "~B" << std::endl;
    }
}; 
class D : public B 
{
public:
    D() {
        std::cout << "D" << std::endl;
    }

    ~D() {
        std::cout << "~D" << std::endl;
    }
};

void Play(B b) 
{
}


int main()
{
    D d;
    Play(d);
    return 0;
}

运行结果如下:


image.png

修改后:

#include <iostream>

class B
{
public:
    B() {
        std::cout << "B" << std::endl;
    }

    B(const B& other) {
        std::cout << "c B" << std::endl;
    }

    ~B() {
        std::cout << "~B" << std::endl;
    }
}; 
class D : public B 
{
public:
    D() {
        std::cout << "D" << std::endl;
    }

    D(const D& other) {
        std::cout << "c D" << std::endl;
    }

    ~D() {
        std::cout << "~D" << std::endl;
    }
};

void Play(B b) 
{
}


int main()
{
    D d;
    Play(d);
    return 0;
}

运行结果如下:


image.png

已经报给visual studio:
https://developercommunity.visualstudio.com/content/problem/1010288/a-class-without-a-explicit-copy-constructor-will-c.html

相关文章

网友评论

      本文标题:Visual Studio 2019的一个BUG

      本文链接:https://www.haomeiwen.com/subject/ofpiwhtx.html