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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:06:22+00:00 2026-06-02T06:06:22+00:00

This is a simple class ive created in C++ for a musical application im

  • 0

This is a simple class ive created in C++ for a musical application im creating for an iOS device which will store some values of notes and their timings :

class info {
public:
    float attackTime;
    Note noteStriked;

    void setData(float timeOfAttack, Note nameOfStrikeNote){
        attackTime = timeOfAttack;
        noteStriked = nameOfStrikeNote;
    }
};

above… Note is a struct which can only contain default values such as {SNARE, DRUM, HIHAT} and so on. The idea is to create a Note object and store those objects in a NSMutableArray for later access.

Then in my main .h file i have a NSMutableArray sequenceOfNotes; and in my .m file i am trying to add an object to my mutablearray… but i dont know how to do this. Ive tried various things but with fail it does not work!

//Create one instance of the class
NoteData *currentNoteData;

// Update the instance of the class.. its two variables: attackTime and noteStriked
currentNoteData->attackTime = timeHit;
currentNoteData->noteStriked = SNARE;

//Then im trying to add the above instance to my mutableArray below
[sequenceOfNotes addObject:currentNoteData];

The error produced on that line is
Cannot initialise a parameter of type ‘id’ with an lvalue of type ‘NoteData *’

what id then like to do after the error is fixed is to be able to retrieve my object at any position of the array i choose and then be able to choose an attribute variable from that object at that specific index.

//PsuedoCode
array {
  position 0: NoteData object {
                attackTime = 45.34,
                noteStriked = HIHAT
              }
  position 1: NoteData object {
                attackTime = 65.32,
                noteStriked = SNARE
              }
  position 2: NoteData object {
                attackTime = 78.53,
                noteStriked = HIHAT
              }
  position 3: NoteData object {
                attackTime = 98.44,
                noteStriked = KICK
              }
  etc etc

}

//and then convert NSObject to normal c++ object something like this... 
NoteData temp = [noteSequence objectAtIndex:0];

//so that i can then do this:
float currentTime = temp.attackTime;
Note currentNote = temp.noteStriked;

Obviously theres a conversion issue.. if anyone can help me with this that would be awesome

  • 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-02T06:06:24+00:00Added an answer on June 2, 2026 at 6:06 am

    You have to wrap your C++ object pointer into a NSValue:

    [MyArray addObject:[NSValue valueWithPointer:new MyCPPObject()]];
    
    ...
    
    MyCPPObject *obj = [[MyArray objectAtIndex:index] pointerValue];
    

    Alternatively, why don’t you just use a vector<MyCPPObject> or a list<MyCPPObject>?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a simple buffer manager class to be used with asyncroneous sockets. This
I've created this simple program in Eclipse: import java.util.*; import java.io.*; public class prob1
I've created simple string class with some extra functions - its mainly for learning
I've built a simple snake game that uses a Main class (this is my
I have this simple class public class Position{ int x; int y; Position(int x,int
take this simple code: class A{ public: virtual void foo() = 0; void x(){
I got this simple cache class setted up as a library in the Codeigniter:
Hai. I was making this simple string class and was wondering if there was
I have this very simple C++ class: class Tree { public: Node *head; };
Suppose you have a simple class like this: class foo{ private: int* mData; int

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.