所以,我正在做一個專案,我在這個專案中有兩個檔案。 main.cpp, matrix.h
問題是,我的代碼在幾個小時前似乎作業得很好,而現在卻不行了
main.cpp:#include <iostream>
#include "matrix.h"
#include <vector>/span>
int main() {
矩陣f。
f. 創建(10, 1, {3, 4, 5, 6, 7, 8, 9})。)
matrix.h:
#pragma once
#include <iostream>
#include <string>
#include <Windows.h>/span>
#include <vector>
class Matrix {
public:
const size_t N。
bool ifMatrixCreated;
const char* NOTENOUGH = "陣列的大小應該與寬度*高度的元素相匹配"。
std::vector<int> arr;
int w, h;
void create(int width, int height, const std: :vector<int> a) {
w = 寬度。
h = 高度。
if (a.size() != width * height) {
ifMatrixCreated = false;
std::cout << "bello"/span>;
}
else {
ifMatrixCreated = true;
arr = a;
std::cout << "hello";
}
}
};
而當我編譯的時候,它產生了這樣的錯誤(使用VS2019):
Error C2280 | 'Matrix::Matrix(void)': attempting to reference a deleted function Matrix | Line 5
它一直說 "Matrix的默認建構式不能被參考 - 它是一個被洗掉的函式"
你能幫助解決這個問題嗎?
你能幫助解決這個錯誤嗎?
謝謝你的幫助。
預先感謝。
uj5u.com熱心網友回復:
這里是正確的作業實體。錯誤的發生是因為每個常量資料成員都必須被初始化。而且
類T的隱式宣告或默認的默認建構式是未定義的(直到C 11),如果以下任何一項為真,則定義為洗掉(自C 11):
- T有一個沒有用戶定義的默認建構式或括號或等價初始化器的const成員(自C 11起)。
#pragma once
#include <iostream>
#include <string>
//#include <Windows.h>
#include <vector>
class Matrix {
public:
//const size_t N;//this const data member must be initialised.
const size_t N = 6;
bool ifMatrixCreated;
const char* NOTENOUGH = "陣列的大小應該與寬度*高度的元素相匹配"。
std::vector<int> arr;
int w, h;
void create(int width, int height, const std: :vector<int> a) {
w = 寬度。
h = 高度。
if (a.size() != width * height) {
ifMatrixCreated = false;
std::cout << "bello"/span>;
}
else {
ifMatrixCreated = true;
arr = a;
std::cout << "hello";
}
}
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/326352.html
標籤:
