0

I have C++ singleton implementation like this:

#include "DoingSomething.hpp"
class DoingSomething
{
    static DoingSomething *shareInstance;

    public:

    int doSomething()
    {
        /*

         */

        return someValue;
    }

    static DoingSomething *instance()
    {
        if (!shareInstance)
            shareInstance = new DoingSomething;
        return shareInstance;
    }
};

But I want to access the singleton and the public functions inside of the singleton on my viewController using Objective-C. Any of you knows how can this be done?

I'll really appreciate your help.

user2924482
  • 8,380
  • 23
  • 89
  • 173
  • adding a `.mm` file ending to your source code turns the file into an objective-c++ source file. It understands both objective-c and c++ in the same source file. – Richard Hodges Apr 17 '17 at 21:38
  • Possible duplicate of [Calling C++ from Objective-C](http://stackoverflow.com/questions/19229574/calling-c-from-objective-c) –  Apr 17 '17 at 21:43
  • @Sneak, to the post are pointing is unclear how to access to C++ singleton. Per one of the post " self.mmclass = [[CplusplusMMClass alloc]init]; // bad practice; but showing code" – user2924482 Apr 17 '17 at 23:05
  • @user2924482 Since you are calling a singleton I don't see why you would need to store the singleton as a property, therefore you dont need to call self.mmclass =.... Did you see the example project linked in the comment section? –  Apr 17 '17 at 23:09

0 Answers0