你好無情社區,今天我指望你的幫助。C++ Union/Struct'printColorPicker :: printColorPicker(void)':嘗試引用已刪除的函數
請不料小白的代碼
的錯誤是在第20行(我會發表評論,所以你可以看到)。
錯誤:「printColorPicker :: printColorPicker(無效)」:試圖引用刪除的功能
#include <iostream>
using namespace std;
enum availableColors {
incolorPrint,
colorPrint
};
union printColorPicker {
struct incolorPrint {
int id;
char* details = "No color ink eh?";
} i;
struct colorPrint{
int id;
char* details = "Unicorn mode on";
} c;
} color; //line 20
void colorPicker(availableColors c){
char* option;
switch (c) {
case incolorPrint: {
option = color.i.details;
}
break;
case colorPrint: {
option = color.c.details;
}
break;
}
cout << option;
}
void main(){
colorPicker(colorPrint);
}
什麼,我要做的是使用顏色選擇器的方法來呼應內/ COUT/printf的字符串printColorPicker
聯盟內的結構(colorPrint
,incolorPrint
)。
我得到了上面提到的錯誤。
所以構造函數應該有'union'的名字,沒有參數? –
TBH我不明白你爲什麼在你的代碼中使用'union'。 –
這是一項功課,工會是其中的一項要求。 –