You are here:

C++/About Dots and Boxes Program

Advertisement


Question
I 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' ;  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.