1

I have an android project with OpenSL ES and need to do some cleaning up.

One of the things I want to do is separate some logic from one file.

The file has the following variable defined:

static SLObjectItf engineObject = NULL; 

This is a C variable as we access it like so:

(*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); 

I am trying to pass it off to another C++ class like so:

audioBuffer->Create(&engineObject); 

This is how you would normally pass a pointer to SLObjectItf but it's a C variable so there is some different behaviour here.

This seems like a fairly straightforward task, here is the recieving function:

AudioBuffer::Create(SLObjectItf* engineEngine) { // .... (*engineEngine)->CreateAudioPlayer(engineEngine, &bqPlayerObject, &audioSrc, &audioSnk, 3, ids, req); } 

And the error is:

request for member 'CreateAudioPlayer' in '* * engineEngine', which is of pointer type 'const SLEngineItf_* const' (maybe you meant to use '->' ?) 

How do I pass a C variable into a C++ function and use it there?

6
  • What is SLObjectItf? And do you really need that many pointer indirections? Commented May 5, 2014 at 7:08
  • @JoachimPileborg It's a struct. Here is the header file: khronos.org/registry/sles/api/1.0/OpenSLES.h Commented May 5, 2014 at 7:09
  • did you try (engineEngine)->.... Commented May 5, 2014 at 7:10
  • Looks like engineObject is pointer to structure, so you don't need to pass pointer to it in audioBuffer->Create(&engineObject);. If you do engineEngine is pointer to pointer so do (*(*engineEngine))->CreateAudioPlayer(...) Commented May 5, 2014 at 7:10
  • it seems like SLObjectItf is a pointer to a pointer to struct. (*engineEngine) first indirection; ->func() second indirection. so your function needs more indirection. Commented May 5, 2014 at 7:11

2 Answers 2

2

When looking at the header file, I see that SLObjectItf is defined as

typedef const struct SLObjectItf_ * const * SLObjectItf; 

That means it's a pointer to pointer to a structure. When you pass a pointer to the SLObjectItf variable you pass a pointer to pointer to pointer to the structure, so *engineEngine is the pointer to pointer to structure. You need another dereference operator, or simply not pass it as a pointer.

Sign up to request clarification or add additional context in comments.

1 Comment

Right, makes sense. I just had to change Create(SLEngineItf* engineEngine) to Create(SLEngineItf engineEngine) and pass engineEngine instead of &engineEngine
0

'engineEngine' is passed as a pointer, try

engineEngine->CreateAudioPlayer(...... 

or

(*engineEngine).CreateAudioPlayer(..... 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.