C
Chris Lieb
I am trying to create a "pseudo-class" using structs. Member variables
seem easy enough to do. However, trying to implement member functions
has led to nothing but frustration. I have tried using function
pointers, but when I do, I cannot figure out how to get access to the
member variables. Here is what I have so far:
typedef struct {
int board[8][8];
void (*toString)();
void (*clear)();
} BOARD;
void printBoard() {
// doing stuff with board
}
void clearBoard() {
// doing stuff with board
}
BOARD newBoard() {
BOARD out;
out.clear = clearBoard;
out.toString = printBoard;
return out;
}
When I try to compile (using GCC), I get "error: 'board' undeclared
(first use in this function)".
Is there a way to accomplish this?
Thanks in advance,
Chris Lieb
seem easy enough to do. However, trying to implement member functions
has led to nothing but frustration. I have tried using function
pointers, but when I do, I cannot figure out how to get access to the
member variables. Here is what I have so far:
typedef struct {
int board[8][8];
void (*toString)();
void (*clear)();
} BOARD;
void printBoard() {
// doing stuff with board
}
void clearBoard() {
// doing stuff with board
}
BOARD newBoard() {
BOARD out;
out.clear = clearBoard;
out.toString = printBoard;
return out;
}
When I try to compile (using GCC), I get "error: 'board' undeclared
(first use in this function)".
Is there a way to accomplish this?
Thanks in advance,
Chris Lieb