#Class object

4 messages · Page 1 of 1 (latest)

teal kiln
#

Hello just wanted to ask how would I use an object in multiple different functions in my file so for example if I have Myclass obj; where would I put that in the file to use it in multiple different functions ?

#

class Myclass {
public: 
    int health;     
}

int main() {
    
    return 0;
}

void render() {
    
}``` where would I put the myclass obj if I had the class in a header file ?
#

would I do it globally or somewhere else

oblique dragon
#

It really depends on how you want to use it. Globals can work, but they're usually not recommended for several reasons (e.g., testability and maintainability), although sometimes they are unavoidable.