Struct+中的C++Struct删除了函数错误
C++ Struct within Struct + deleted function error
我在一个项目中有一个头文件,我在其中声明了许多结构。后一种结构的某些成员是先前声明的结构的类型。我知道这些成员结构在使用之前必须声明,但我遇到了一种奇怪的行为。
在下面的文件中,我尝试向类型为Coordinate
的第二个结构(LUT)
添加一个新成员。正如你所看到的,底部结构体libraryEntry
有一个类似的成员;这种情况已经持续了一段时间,没有造成任何问题。
#ifndef STRUCTS_H
#define STRUCTS_H
#pragma once
#include <string>
#include "Enums.h"
struct Coordinate {
int X;
int Y;
Coordinate(int x, int y) : X(x), Y(y) {}
};
struct LUT {
int offset;
std::string hexCode;
bool modifiedByTrojan;
//Coordinate xyCoordinate; <======= Causes build to fail when uncommented
};
struct libraryEntry {
int id;
DeviceType deviceType;
int offSet;
Coordinate xyCoordinate;
std::string hexCode;
DeviceConfiguration deviceConfig;
libraryEntry(int idNum, DeviceType deviceType, int offSet, Coordinate xyCoordinate, std::string hexCode) :
id(idNum),
deviceType(deviceType),
offSet(offSet),
xyCoordinate(xyCoordinate),
hexCode(hexCode)
{
}
};
#endif
添加上面的坐标成员会导致错误:
'LUT::LUT(void)':attempting to refernce a deleted function
为什么这只发生在第二个结构中?
在工作的结构(libraryEntry
)中,您定义了一个构造函数,并且在构造函数中,您正在使用它的两个arg构造函数初始化xyCoordinate
。
在编译失败的结构中,您没有定义任何构造函数,因此您获得了默认的无arg构造函数,它使用它们的默认(无arg)构造函数初始化所有内容,包括Coordinate
成员。Coordinate
没有默认构造函数,因为您声明了一个不同的构造函数,这导致默认构造函数被删除,因此出现错误消息。
相关文章:
- "error: no matching function for call to"构造函数错误
- 为什么类中的ostringstream类型的成员会导致";调用隐含删除复制构造函数";错误
- 尝试将unique_ptrs推送到向量时使用纯虚拟函数错误
- C++ OpenCV 卡尔曼滤波器构造函数错误
- C++:用户定义的显式类型转换函数错误
- C++ 合并字符串以'system'函数错误
- C++ wmain 函数错误时使用 Unicode
- 结构数组的构造函数错误,错误消息:没有构造函数实例与参数列表匹配
- C++ 中常量属性的初始化构造函数错误
- 线程 std::调用未知类型,无法专门化函数错误
- 表单显示对话框函数错误,并且不执行下面的语句
- 函数错误 C2059:语法错误:'>'不起作用
- STL向量上出现奇怪的复制构造函数错误
- C++ Visual Studio 重载函数错误:没有重载函数的实例与指定的类型匹配
- C++引用已删除函数错误
- 为什么通过带有文字编号的引用调用会出现"无匹配函数"错误?
- C++ 乘法定义的构造函数错误消息似乎错误
- 在 c++ 代码中将数组传递给函数错误
- FFMPEG avcodec_decode_video2函数错误代码
- 为什么我会收到转换函数错误