我想在C++ Eclipse來寫一個Qt程序,但我不能讓過去的錯誤:無效參數
void MyTests::populateFirstList(){
Question* q = new Question;
q = this->ctr->getCurrent();
string s = this->ctr->toString(q);
}
問題是我定義的類型,以及帶有toString(q)的行會返回一個錯誤,指出無效參數。 的funcion的toString():
string Controller::toString(Question* q){
string s="";
string text = q->getText();
char c;
string::iterator it;
for (it= text.begin(); it != text.end(); it++)
{
if ((*it) == ' ') {
s+="\n";
}
else {
s+=it;
}
}
return s;
}
而只是爲了安全起見,功能getCurrent():
Question* Controller::getCurrent(){
return this->question;
}
我不明白爲什麼會這樣,因爲函數的toString()應一個指向問題的指針,q是一個。我甚至不確定這些錯誤是由這些函數還是在更深的地方引起的。謝謝你的幫助。
的錯誤信息是:
invalid arguments ' Candidates are:
std::basic_string < char,std::char_traits <char>, std::allocator <char> >
toString(Question *) '
1.什麼是錯誤? 2.你用'Question * q = new Question;'分配一個內存,下一行殺死一個指針:'q = this-> ctr-> getCurrent();' – borisbn
**確切**錯誤信息,請! –
@borisbn我不確定第一個問題應該是什麼意思,至於第二個,q是一個指針,通過這個函數,不是嗎?其實我對指針很困惑。 – user1796659