有兩個文件一個是.cpp文件另一個是.h文件中,頭文件函數調用
這個類是目前在.h文件中
class DecodeTheCode
{
public:
char* decodeCode(char* encodedString);
};
現在的軟件,我是使用要求
•實現功能的char你的邏輯* decodeCode(字符* encodedString)
但我已經宣佈
const char* decodeCode(const char* encodedString)
{
const char* decodedString = "";
const char* a = encodedString;
char store[10000];
for(int j=0;j<strlen(a);j++)
{
if (isdigit(a[j]) || a[j] == '#')
continue;
else return "";
}
int i = 0,k=0;
while (i < strlen(a))
{
if (a[i] == '#') {i++; continue;}
else if(a[i] == a[i+1] && a[i+1] == a[i+2] && a[i+2] == a[i+3])
{
store[k++] = four(a[i]);
i += 4;
}
else if (a[i] == a[i+1] && a[i+1] == a[i+2])
{
store[k++] = three(a[i]);
i += 3;
}
else if (a[i] == a[i+1])
{
store[k++] = two(a[i]);
i += 2;
}
else
{
store[k++] = one(a[i]);
i++;
}
}
store[k]='\0';
decodedString=store; // line number 103
return decodedString;
}
在.cpp文件現在的軟件顯示
Error(s) encountered:
C:/Users/ADMINI~1/AppData/Loca/Temp/cco5baaa.o(.text+0x18f):TestDecodeTheCode.cpp:undefined reference to
DecodeTheCode::decodeCode(char*)'
C:/Users/ADMINI~1/AppData/Local/Temp/cco5baaa.o(.text+0x1a4):TestDecodeTheCode.cpp: undefined reference to `DecodeTheCode::decodeCode(char*)'
C:/Users/ADMINI~1/AppData/Local/Temp/cco5baaa.o(.text+0x24d):TestDecodeTheCode.cpp: undefined reference to `DecodeTheCode::decodeCode(char*)'
C:/Users/ADMINI~1/AppData/Local/Temp/cco5baaa.o(.text+0x262):TestDecodeTheCode.cpp: undefined reference to `DecodeTheCode::decodeCode(char*)'
C:/Users/ADMINI~1/AppData/Local/Temp/cco5baaa.o(.text+0x30b):TestDecodeTheCode.cpp: undefined reference to `DecodeTheCode::decodeCode(char*)'
C:/Users/ADMINI~1/AppData/Local/Temp/cco5baaa.o(.text+0x320):TestDecodeTheCode.cpp: more undefined references to `DecodeTheCode::decodeCode(char*)' follow
collect2:LD返回1個退出狀態
/decodethecode/decodethecode.c: In function `char* decodeCode(const char*)':
/decodethecode/decodethecode.c:103: error: invalid conversion from `const char*' to `char*'
我使用 爲const char * decodeCode(const char * encodedString) 代替 的char * decodeCode(字符* encodedString) ,否則我得到棄用從字符串常量「字符*」
你有什麼想法,我怎麼能修復它轉換?如果是這樣,請清楚寫下來(我是新手......)。
可以請你告訴我應該如何將store []傳遞給decodeString;我使用store []只是爲了使它成爲一種字符串,以便我可以使用返回函數傳遞它。 – user1590595
@ user1590595,最簡單的方法就是'返回std :: string(store);'並將返回類型改爲'std :: string'。這是否允許? – hmjd
不,我不能更改.h文件,並且返回類型必須相同。你能弄清楚別的嗎? – user1590595