C++/About Dots and Boxes Program
Expert: vijayan - 11/28/2011
QuestionI read your previous post on the dots and boxes codes. I have a question relating to the same.
How do we declare the following function-
void print_grid(const grid_t& grid, std::ostream& stm)
Also when we use it
Is it ok to use it as the following?
print_grid(grid, strd:: cout)
Would it not be illegal to convert void to int. I have errors when trying to use it that way. I do not know what the problem is? Please help!!
Answer> How do we declare the following function-
void print_grid(const grid_t& grid, std::ostream& stm)
Just declare it as it is:
void print_grid(const grid_t& grid, std::ostream& stm)
; // a semicolon is required at the end
> Is it ok to use it as the following?
print_grid(grid, strd:: cout)
Yes; this would be perfectly fine:
print_grid(grid, strd:: cout)
; // a semicolon is required at the end
> Would it not be illegal to convert void to int. I have errors when trying to use it that way.
Yes, it would be illegal. You can't use the return value of
print_grid() , it returns
void .
This is fine:
print_grid(grid, strd:: cout) ;
These are not:
std::cout << print_grid(grid, strd:: cout) ;
int x = print_grid(grid, strd:: cout) ;
print_grid(grid, strd:: cout) << '\n' ;