我有一箇舊的C++代碼,並且編譯進C++ builder 5中。 但是現在,我需要將此代碼更新/遷移到C++ builder 2009。所以,我有一些問題:非常量函數_fastcall TStrings :: GetCount()爲const對象調用
int __fastcall TAllConversor::ListToStr(
const TStringList* pList,
AnsiString& strValue,
const long lngLimiteInferior,
const long lngLimiteSuperior) const
{
long lngIndice;
AnsiString strAux;
try
{
if (lngLimiteSuperior == 0)
lngIndice = pList->Count;
else
lngIndice = lngLimiteSuperior + lngLimiteInferior;
for (int i = lngLimiteInferior; i < lngIndice; i++)
{
strAux += pList->Strings[i] + ";";
}
strValue = strAux;
return 1;
}
catch(...)
{
return 0;
}
}
在行「lngIndice = pList-> Count;」我得到這個錯誤:「對const對象調用E2522非const函數_fastcall TStrings :: GetCount()」。
那麼,我該如何解決(解決)它呢?
在這段代碼中,我還沒有看到任何關於「TStrings :: GetCount()」?你打了什麼電話?從錯誤,我明白函數的聲明和定義不匹配或用const對象調用函數,但你不應該這樣做。答案:使用Casting – 2012-07-12 13:55:13
我們需要看到一些關於TStringList的信息,因爲這可能是不正確的,那就是代碼改變 – Mark 2012-07-12 13:58:00
@gcc:'TStringList'是一個VCL類。它的'Count'屬性調用'GetCount()'方法。 – 2012-07-12 22:42:38