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

1
  • 1
    Could you post what you've done so far? Commented Oct 11, 2012 at 20:30

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.