我正在學習C++,並且在我正在做的任務中,我收到了一堆警告,我懷疑這些警告正在導致我得到的兩個錯誤。問題在於警告顯示的行是他給我們的行(其中之一),所以我認爲代碼必須是正確的。這使我相信我的類聲明或構造函數中存在一個問題。任何人都可以發現任何錯誤轉換警告。和類錯誤
警告(用於fillSystemCommandList函數的每一行)是從字符串文字爲「字符*」 轉換已被棄用
,並且錯誤是用於建築x86_64的 未定義符號: 「COMMAND: :COMMAND(字符*,INT)」,從引用:在system_utilities.o LD fillSystemCommandList():符號(多個)未找到架構x86_64的 鐺:錯誤:連接命令,退出代碼1(使用失敗 - v看到調用)
你或許可以跳過ParseCommandLine函數,我認爲沒關係。我只是把它包括在內,以便我可以擁有整個文件(這不是我的主要btw)。
其他說明: -systemCommands數組應該是COMMAND指針,長度爲NUMBER_OF_COMMANDS(我想我是這麼做的right)
-fillSystemCommandList函數應該填充systemCommands數組,其結構包含指向命令字符串和相應定義的常量的指針。
- 我知道這段代碼幾乎都是C,而這又是因爲我正在使用的類是一個開始的C++類。
#include "system_utilities.h"
#include "definitions.h"
using namespace std;
int getCommandNumber(char *s);
class COMMAND {
char* pointertochar;
int* pointertoint;
public:
COMMAND(char*, int);
int amIThisCommand(char*);
};
int COMMAND::amIThisCommand(char* command){
return 0;
}
COMMAND* systemCommands[NUMBER_OF_COMMANDS];
int parseCommandLine(char cline[], char *tklist[]){
int i;
int length; //length of line
int count = 0; //counts number of tokens
int toklength = 0; //counts the length of each token
length = strlen(cline);
for (i=0; i < length; i++) { //go to first character of each token
if (((cline[i] != ' ' && cline[i-1]==' ') || i == 0)&& cline[i]!= '"') {
while ((cline[i]!=' ')&& (cline[i] != '\0') && (cline[i] != '\r')){
toklength++;
i++;
}
//---------------
tklist[count] = (char *) malloc(toklength +1);
memcpy(tklist[count], &cline[i-toklength], toklength);
tklist[count][toklength]='\0';
//cout << "\n" << tklist[count] << "\n";
//cout << "\n" << i << "\n";
//cout << "\n" << toklength << "\n";
//--------------
count ++;
toklength = 0;
}
if (cline[i] == '"') {
do {
toklength++;
i++;
/*if (cline[i] == ' ') {
toklength--;
}*/
} while (cline[i]!='"');
//--------------
tklist[count] = (char *) malloc(toklength +1);
memcpy(tklist[count], &cline[i-toklength+1], toklength-1);
tklist[count][toklength]='\0';
//cout << "\n" << tklist[count] << "\n";
//cout << "\n" << i << "\n";
//cout << "\n" << toklength << "\n";
//--------------
count ++;
toklength = 0;
}
}
return count;
}
int getCommandNumber(char *s) {
/*switch (*s) {
// case "halt":
return HALT;
break;
default:
break;
}*/
return 0;
}
void fillSystemCommandList() {
systemCommands[0] = new COMMAND("halt", HALT);
systemCommands[1] = new COMMAND("status", STATUS);
systemCommands[2] = new COMMAND("time_click", TIME_CLICK);
systemCommands[3] = new COMMAND("new_sensor", NEW_SENSOR);
systemCommands[4] = new COMMAND("new_sensor_node", NEW_SENSOR_NODE);
systemCommands[5] = new COMMAND("new_network", NEW_NETWORK);
systemCommands[6] = new COMMAND("add_sensor_to_node", ADD_SENSOR_TO_NODE);
systemCommands[7] = new COMMAND("add_node_to_network", ADD_NODE_TO_NETWORK);
systemCommands[8] = new COMMAND("sensor_command", SENSOR_COMMAND);
}
再次感謝您的幫助,您可以給!