In a struct (or class), I know that I can add a function and then call it later.
struct State {
int turnsLeft;
void nextTurn() {
turnsLeft--;
}
};
State s1{1};
State s2{2};
s1.nextTurn();
My question is, how do these functions relate to how much space the struct takes up? I know a int is 4 bytes and so creating s1 and s2 costs at least 4*2=8 bytes. But, will a new copy of this function be created each time that I make a new struct, or will only one copy of the function be made and shared no matter how many different State functions I make? If the function is copied each time, how can I write the code so that only one copy of the function is made? A static function doesn't work very naturally, since I want to access this when I modify turnsLeft.