我需要致電我的公共成員。構造函數需要1個參數。使用** ClassObject調用公共成員(C++)
這是我的代碼的外觀: //主
char tmpArray[100] = {};
while (!inFile.eof())
{
for (unsigned x = 0; x < str2.length(); x++)
{
if (!isspace(str2[x]) || isspace(str2[x]))
{
tmpArray[x] = str2[x]; // prepare to supply the constructor with each word
ClassObject[wrdCount] = new ClassType[x] ;
//ClassObject[wordCount]->ClassType(tmpArray);
}
}
}
的錯誤是:
'功能樣式轉換':非法作爲 右側 ' - >' 操作
要嘗試解決問題,我嘗試兩個等效表達式:
/* no good */ (*ClassObject[wrdCount]).ClassType(tmpArray);
/* no good */ (*ClassObject[wrdCount][10]).ClassType(tmpArray);
/* combine */ ClassObject[arbitrary][values]->ClassType(tmpArray);
智能感知確實會帶出除構造函數之外的所有我的成員和私有者。 這可能是原因嗎?
//MyHeader.h
class ClassObject
{
private:
const char* cPtr;
float theLength;
public:
ClassObject(const char*); // Yes its here and saved..
ClassObject(); // an appropriate default constructor
~ClassObject();
char GetThis();
char* GetThat();
}
你能發佈整個代碼嗎?我不明白你是如何擁有一個ClassObject類的,並且也使用ClassObject作爲指針。 – Uri 2009-04-12 05:33:41
我是否缺少某些東西,或者是「if(!isspace(str2 [x])|| isspace(str2 [x]))」總是會評估爲true? – Venesectrix 2009-04-13 15:53:22