Hi, I'm new in object oriented programming.
I need help creating a global object/instance of a class, that can be used by any function.
Does anyone knows a solution?
Please feel free to write it.
If the global can be used from any function, be sure that the functions:
a) Cannot be used at the same time OR
b) Each function tries to lock a mutex so other functions will fail on attempt, thus not resulting in a race condition.
Ok. Thanks.
and how can I make a programm, eyerytime a key is pressed(or something like this) a new objekt/instance of a class is created, that can be used as global?
1. Global variables are bad
2. If you want to start dealing with key presses, you should move on to creating graphical windows and using a graphics library like SFML or SDL.
the problem aren't the keys.
the problem is, to create an undefined number of instances/objects of a class, that can be used by all functions in this programm.
If you want a different name for each one instead of a different number, try std::map<std::string, MyClass>. But this sounds like you're trying to replicate global variables and in a bad way. Can you be more precise about what you're trying to do?
I want to programm where every object is displayed as a dot. When you press a key( or some other event) a new dot will be displayed.
I know how to display and react on keys.
But I don't know how to manage this with classes.
redisplayed every time.
in a line or whatever doesn't matter, because the objects have their position and will by displayed by their on function: draw().