Reputation: 11
here is my code
#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
}
The statements between the **..**, there were the error occured. saying that expected primary - expression s and expected primary - expression st
and the square.h had class Square and SqState.
please help me where is the actuall problem is
Upvotes: 1
Views: 1092
Reputation: 42924
Considering this code:
SqState sq('-', 4, 0); sq.print(ostream s);
You can note that SqState
has a method named print()
, that is defined here:
ostream& SqState :: print(ostream& sq) { return sq << "value: " << sq_value; }
So, the parameter to this print()
method is a reference (&
) to an instance of ostream
(actually, std::ostream
).
You should provide that instance at the call site, and an option is std::cout
to print text on the standard console output:
sq.print(std::cout);
Similarly, for the other code in the testSquare()
function.
Upvotes: 2
Reputation: 662
**sq.print(ostream s);**
**s.print(ostream st);**
You don't need to put ostream there, assuming s and st are already defined.
Upvotes: 0
Reputation: 1
You probably meant to write something like
void testSqState() {
SqState sq('-', 4, 0);
sq.print(std::cout);
}
void testSquare() {
Square s(4, 0);
s.print(std::cout);
}
Upvotes: 1