c++ - 为什么这个 C++ 构造函数会自动指向复制构造函数?

标签 c++

我得到了

Severity    Code    Description    Project    File    Line    Suppression State
Error    C2280    'World::World(const World &)': attempting to reference a
deleted function

在调用行作为错误(因为我的类中没有复制构造函数)

World wd = World(&vp, am);

这是一个构造函数。

我很困惑为什么复制构造函数会被自动定向到。

有人知道吗?

这是我的类标题:

class World{
    public:
        KDtree tree;
        ViewPlane *vp;
        DrawPanel * paintArea = &(DrawPanel(wxString("test"), wxDefaultPosition, 400,400));
        wxApp app;
        Vector3d backGround;
        vector <Geometry*> objects;
        Shader shader;
        vector<Light*>lights;

        World(ViewPlane*, Vector3d& Am);
        ....
}

还有我的构造函数:

World::World(ViewPlane * v, Vector3d &Ambient){
    vp = v;
    shader = (Shader(Ambient));
}

最佳答案

使用

Bar b = Bar(...)

语法确实进行复制初始化:https://en.cppreference.com/w/cpp/language/copy_initialization

你可能只想要

World wd(&vp, am);

相反。

关于c++ - 为什么这个 C++ 构造函数会自动指向复制构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52910335/

相关文章:

java - 是否可以重写 Random 类的 Java 实现?

c++ - 如何将 'convert' 的 Hz 量转换为适当的字节/位格式?

c++ - 如何比较指针?

c++ - 用于 Sutter 的无锁队列的 Boost 库或 C++0x 原子的等效实现?

c++ - QtConcurrent::run 正确使用

c++ - Armadillo C++ 和 BLAS 和 ATLAS 在 mingw32 下找不到 lapack blas

c++ - 使用精确大小的整数c++

c++ - QML QWidget 容器

c++ - 在 u16 中转换 u8[] 时如何强制对齐错误?

c++ - 使用 std::find() 搜索多个元素