Skip to main content
gamedev.net
🔒 Locked

friend function

Started by up in flames 1 reply 350+ views
Original Post
up in flames
up in flames
I was going through an old program to make it a little more readable - implementing classes - and I have run into the problem of printing the board from my board function after the user inputs a choice to start a game. I have tried reading from my book to explain how to do this correctly but it leads me in circles. Am I going about using the printBoard() function from another class within my printMenu() function in my menu class by making printBoard() a friend function? If so how would I complete this task withOUT errors? in Menu Class: friend void printBoard(void); No Definition in Menu CLass in Board Class void Board::printBoard(void) { // assuming that the board array is alread declared for(char a = 0; a < 9; a++) board[a] = ' '; cout << " " << "|" << " " << "|" << " " << endl; cout << " " << board[0] << " " << "|" << " " << board[1] << " " << "|" << " " << board[2] << " " << endl; // previous lines of code are re-written until I reached board[8] << " " << endl; }
Kenjutsu maybe a lost art, but tell me I'm stupid for wanting to take a knife toa gunfight after watching this http://www.comegetyousome.com/misc/videos/bulletvskatana.wmv
ToohrVyk
ToohrVyk
friend void Board::printBoard allows you to use the Menu class in the Board::printBoard function.


JasonBlochowiak
JasonBlochowiak
Neverminding that Board::printBoard() is redundant...

Any reason that Board::print() shouldn't be public? Doesn't seem like the sort of function that would need to be restricted to the class or any friend classes or functions.

There are a bunch of other issues, but they're less on topic.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.