[英]expected primary expression before object c++
這是我的代碼
#include "Square.h"
#include "tools.hpp"
ostream&
Square :: print(ostream& s)
{
return s << "Square [" << row << " " << column << "]" << endl;
}
ostream&
SqState :: print(ostream& sq)
{
return sq << "value: " << sq_value;
}
void testSquare();
void testSqState();
int main()
{
banner();
testSquare();
testSqState();
bye();
}
void testSqState()
{
SqState sq('-', 4, 0);
sq.print(ostream s); // << Error occurs here
}
void testSquare()
{
Square s(4, 0);
s.print(ostream st); // << Error occurs here
}
** .. **之間的陳述,發生了錯誤。 說預期的初級表達和預期的初級表達st
square.h有類Square和SqState。
請幫幫我,實際問題在哪里
考慮這段代碼:
SqState sq('-', 4, 0); sq.print(ostream s);
您可以注意到SqState
有一個名為print()
的方法,它在此處定義:
ostream& SqState :: print(ostream& sq) { return sq << "value: " << sq_value; }
因此,此print()
方法的參數是ostream
實例的引用 ( &
)(實際上是std::ostream
)。
您應該在調用站點提供該實例,並且選項是std::cout
以在標准控制台輸出上打印文本:
sq.print(std::cout);
同樣,對於testSquare()
函數中的其他代碼。
你可能想要寫一些類似的東西
void testSqState() {
SqState sq('-', 4, 0);
sq.print(std::cout);
}
void testSquare() {
Square s(4, 0);
s.print(std::cout);
}
**sq.print(ostream s);**
**s.print(ostream st);**
假設s和st已經定義,你不需要在那里放置ostream。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.