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 583163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:45:50+00:00 2026-05-13T14:45:50+00:00

I have some Objective-C++ code that I’m trying to get events out of an

  • 0

I have some Objective-C++ code that I’m trying to get events out of an Objective-C object to call a method within a C++ object. I’m very new to Objective-C, so I may be doing this all wrong.

Example:

@interface KnobClass {
}
-(void)Event;
@end

class DoorClass {
    public:
    KnobClass * knob;
    void start() { knob = [[KnobClass allocate] init]; }
};

class AlarmClass {
    public:
    void Alert();
};

class HouseClass {
    public:
    DoorClass door;
    AlarmClass alarm;
};

int main() {
    //...
    HouseClass house;
    house.door.start();
    //...
    return 0;
}

The method [house.door.knob Event] is generated on an event, and I want it to be able to call house.alarm.Alert(). But I’m confused how to accomplish this in a correct manner. Can someone suggest a way of accomplishing this?

  • 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-05-13T14:45:50+00:00Added an answer on May 13, 2026 at 2:45 pm

    I’m learning Objective-C too. This works in gcc 4.3.3:

    #import <Foundation/Foundation.h>
    
    class AlarmClass {
        public:
        void Alert() {
            printf("Alert!\n");
        }
    };    
    
    @interface KnobClass: NSObject {
        AlarmClass *alarm;
    }
    -(void)Event;
    -(id)initWithAlarm:(AlarmClass*) alarm;
    @end
    
    @implementation KnobClass: NSObject
    
    -(id)initWithAlarm:(AlarmClass*) a
    {
        self = [super init];
        alarm = a;
        return self;
    }
    
    -(void)Event
    {
        alarm->Alert();
    }
    @end
    
    class DoorClass {
        public:
        KnobClass * knob;
        void start(AlarmClass *a) {
            knob = [[KnobClass alloc] initWithAlarm: a];
        }
    
        void doEvent() {
            [knob Event];
        }
    };
    
    class HouseClass {
        public:
        DoorClass door;
        AlarmClass alarm;
    };
    
    int main(int argc, const char *argv[]) {
        //...
        HouseClass house;
        house.door.start(&house.alarm);
        house.door.doEvent();
        //...
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some Objective-C code that looks like this: #define myVar 10 float f
I have some objective-c code that uses an NSLock to implement a sort of
I have some Objective-C code that does the job for me. But is it
I'm trying to get started with Phonegap. I have added some code to applicationDidFinishLaunching
I have inherited some code that will eventually be part of an API call.
I'm very new to Objective-C, and am having some beginner issues. I have an
I have some jquery code that is doing an ajax lookup and returning comma
I have some python code for Google App Engine that responds with the string
I have some high-performance C++ that I need to interface with Objective-C, is there
Doing a small project I have received some Java code that I should rewrite

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.