0

I'm not very skilled in C++, so I find this tricky.

I have a class which looks pretty similar to this one : Is it possible to use signal inside a C++ class?., but inside the signal handling method I have to work with an instance variable.

The first thing I tried was to set the variable static, but it didn't help. What should i do? Thanks Hynek

Community
  • 1
  • 1
Hynek Blaha
  • 633
  • 2
  • 6
  • 8

1 Answers1

1

If you want to work with an instance variable, then you'll need a class instance, since you cant access instance variables from a static method. Your next question will be how to get the class instance, for which there are a few options. You can either make a global variable, which is usually frowned upon, or you could consider making a Singleton. The approach used in option 2 of the accepted answer to the question you referenced is similar to a singleton, so that could also be an option.

Perhaps this would be clearer if you reviewed static methods and attributes. Bruce Eckel's Thinking in C++ is an excellent free online c++ book that should help.

Brady
  • 10,207
  • 2
  • 20
  • 59