views:

77

answers:

5

Hi I am using a 3rd party library in my iPhone application that uses C++ one of the methods i need to use returns a pointer to a pointer of a class. like follows.

DLL classAttributes** getAttributes();

I can successfully call the method and return the value into a pointer to a pointer like so;

classAttributes **attributes = cPPClass->getAttributes();

however i can't seem to access any of the methods on the class for example i know that the class has a function called getName(); but when i try calling it i get errors.

attributes->getName(); 'Request for member 'getName' in *attributes'; which is of non-class type 'attributes*''

I did some googling and found some stuff that said to access a pointer pointer address use the format

&(*attributes)->getName(); 'invalid uses of incomplete type 'struct attributes'

Any help would be much appreciated. Thanks.

+1  A: 

Without knowing more about the library, it's hard to say. But it could be returning an array of items:

attributes[0]->getName();    
attributes[1]->getName();

The questionable part about my guess, though, is that there is no obvious way to know how many items there are.

Mark Wilkins
Note that `attributes[0]->getName()` is equivalent to `(*attributes)->getName()`.
Kristopher Johnson
@Kristopher: Yes - I know that. I'll try to clarify my meaning. I added another entry to show more "array-like" usage (and a caveat that indicates I would not know how many items there are). Thanks.
Mark Wilkins
+1  A: 

First consider what you would do if the function returned a pointer to a classAttributes variable. In this case, you would simply do:

attributes->getName();

Since it's a pointer to a pointer, you must first dereference it and then use the -> operator:

(*attributes)->getName();

If this doesn't work, it may be a problem caused by the function not being implemented or by inheritance.

starghost
Fixed the formatting for you, hope you don't mind.
You
Hi Guys, I tried both those suggestions (*) and [0] but i still get the same error:: invalid use of incomplete type
Anthony McCormick
Sounds like Alex might be correct then.
Nate Zaugg
+1  A: 

What you probably want is a classAttributes*. Since you have a classAttribues** , you want to dereference it once to get to the classAttributes*.

(*attributes)

From there you can probably call the members of the class.

classAttributes **attributesArray = cPPClass->getAttributes();
classAttributes *attributesObject(*attributesArray);
attributesObject->getName();
Phil Gilmore
A: 

By the looks of it, you'd probably have to do is this way (i.e. no ampersand):

(*attributes)->getName();

This is because dereferencing it once will give you a pointer to a struct, on which you can then use the -> operator. What's happening when you do &(*attributes) is that you're dereferencing the pointer, then getting the address of the object you have — in effect making it a no-op.

You
+2  A: 

'invalid uses of incomplete type 'struct attributes' indicates that you need to #include the header file for it. It's only forward-declared at this point in your code.

Alex Emelianov