As the title says. How would I create an instance of a class that is globally available(for example I have a functor for printing and i want to have a single global instance of this(though the possibility of creating more)).
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Going to all the effort of making a singleton object using the usual pattern isn’t addressing the second part of your question – the ability to make more if needed. The singleton ‘pattern’ is very restrictive and isn’t anything more than a global variable by another name.
Now, in any other module just include
myclass.hand useg_MyClassInstanceas usual. If you need to make more, there is a constructor ready for you to call.