相关疑难解决方法(0)

"没有合适的默认构造函数" - 为什么甚至调用默认构造函数?

我已经看了一些关于这个问题的其他问题,但我不明白为什么在我的情况下甚至应该调用默认构造函数.我可以提供一个默认的构造函数,但我想了解它为什么这样做以及它会影响什么.

error C2512: 'CubeGeometry' : no appropriate default constructor available  
Run Code Online (Sandbox Code Playgroud)

我有一个名为ProxyPiece的类,其成员变量为CubeGeometry.构造函数应该接受CubeGeometry并将其分配给成员变量.这是标题:

#pragma once
#include "CubeGeometry.h"

using namespace std;
class ProxyPiece
{
public:
    ProxyPiece(CubeGeometry& c);
    virtual ~ProxyPiece(void);
private:
    CubeGeometry cube;
};
Run Code Online (Sandbox Code Playgroud)

和来源:

#include "StdAfx.h"
#include "ProxyPiece.h"

ProxyPiece::ProxyPiece(CubeGeometry& c)
{
    cube=c;
}


ProxyPiece::~ProxyPiece(void)
{
}
Run Code Online (Sandbox Code Playgroud)

立方体几何体的标题如下所示.使用默认构造函数对我没有意义.我还需要吗?:

#pragma once
#include "Vector.h"
#include "Segment.h"
#include <vector>

using namespace std;

class CubeGeometry
{
public:
    CubeGeometry(Vector3 c, float l);

    virtual ~CubeGeometry(void);

    Segment* getSegments(){
        return segments;
    }

    Vector3* getCorners(){
        return corners;
    }

    float getLength(){
        return length;
    } …
Run Code Online (Sandbox Code Playgroud)

c++ constructor member default-constructor

13
推荐指数
2
解决办法
3万
查看次数

标签 统计

c++ ×1

constructor ×1

default-constructor ×1

member ×1