main.cpp
Код: Выделить всё
#include "turn.h"
#include
void subfunc(Turns t) {
printf("%d\n", t);
}
void func() {
Turns colour = getTurn(&turn);
subfunc(colour);
}
int main() {
setTurn(&turn, WHITE);
func();
return 0;
}
Код: Выделить всё
#include "turn.h"
extern Turn turn;
void setTurn(Turn *t, Turns newTurn) {
t->turn = newTurn;
}
Turns getTurn(Turn *t) {
return t->turn;
}
void changeTurn(Turn *t) {
if (t->turn == WHITE) {
t->turn = BLACK;
} else {
t->turn = WHITE;
}
}
Код: Выделить всё
#ifndef TURN_H
#define TURN_H
enum Turns {WHITE, BLACK};
typedef struct {
Turns turn;
} Turn;
void setTurn(Turn *t, Turns newTurn);
Turns getTurn(Turn *t);
void changeTurn(Turn *t);
#endif
Подробнее здесь: https://stackoverflow.com/questions/791 ... other-file
Мобильная версия