1

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.

Anthony McCormick
  • 2,724
  • 3
  • 25
  • 27
  • 2
    Do you know what the `->`, `*`, and `&` operators do? If not, you need to find [a good introductory C++ book](http://stackoverflow.com/questions/388242/the-definitive-c++-book-guide-and-list) and learn what they are. You can't stumble through programming C++ by trying random combinations of operators. – James McNellis Sep 29 '10 at 23:05

5 Answers5

2

'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
  • 1,254
  • 10
  • 10
1

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
  • 40,729
  • 5
  • 57
  • 110
  • 1
    Note that `attributes[0]->getName()` is equivalent to `(*attributes)->getName()`. – Kristopher Johnson Sep 29 '10 at 23:03
  • @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 Sep 29 '10 at 23:06
1

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.

You
  • 22,800
  • 3
  • 51
  • 64
user
  • 7,123
  • 7
  • 48
  • 90
1

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
  • 1,286
  • 8
  • 15
0

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
  • 22,800
  • 3
  • 51
  • 64