Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9035271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:43:03+00:00 2026-06-16T08:43:03+00:00

I have a pure C++ class that needs to retrieve an int value from

  • 0

I have a pure C++ class that needs to retrieve an int value from some Objective-C instance method.

I understand that C++ cannot call Objective-C methods directly.

I have an Objective-C++ class that allows me to work with Objective-C and also to pass data to my pure C++ class.

However, I have not figured out a way to allow the pure C++ class to request the int value be computed and retrieved. In other words, the pure C++ needs to be able to retrieve that value whenever it needs to (via a function pointer, or whatever).

Anyone know how this is accomplished?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:43:04+00:00Added an answer on June 16, 2026 at 8:43 am

    C++ can definitely call Objective-C code. Store the code that communicates in a .mm file instead of .cpp, and Xcode will do the rest for you.

    .mm files store Objective-C++ code, which is why it works.

    [Edit]
    You probably have some business logic in C++, and want to combine that with your UI in Objective-C, right? Your business logic is probably shared across multiple platforms, which is why you can’t just compile all your code as Objective-C++.

    That’s why you can basically “wrap” your Objective-C code in an Objective-C++ wrapper.

    // myUI.h (C++ header)
    class myUI {
        void doSomething1();
        int doSomething2();
    }
    
    // main.cpp (C++ code)
    int main() {
        myUI ui;
        printf("%d\n", ui.doSomething2());
        ui.doSomething1();
        return 0;
    }
    
    // myUI.mm (Objective-C++ code)
    int myUI::doSomething2() {
        return [[MyController sharedController] doSomething2];
    }
    
    // myUI.cpp (C++ code)
    void myUI::doSomething1() {
        printf("Hi!\n");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a pure virtual method in the base interface that returns to
I have a bit of pure C++ code which is reading from Objective-C data
I have a pure virtual class CF that denotes any continuous function in 1D
Any idea how to initialize .NET delegate that points to method from 'mixed' class
If have a union that currently foresees some simple data types: union Value {
my question is rather simple, if you have an pure virtual class (interface) but
I have an abstract class with a pure virtual function f() and i want
Do interfaces (polymorphic class solely with pure virtual functions) have a vtable? Since interfaces
I have a function X() declared as PURE VIRTUAL in base class: class Base
I have a pure ActionScript 3 project that I build using the open source

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.