This one is a little strange to me.
I have a pointer to a class member (mGeometry), which, in turn, holds a pointer to a QList< GLushort > data member (mFaces). I am trying to get the index of mFaces via the class Cube.
So, the more simplified version would look like this:
struct Geometry
{
Geometry( void );
~Geometry( void );
void someFunc( void );
QList< GLushort > *mFaces;
};
class Cube
{
public:
Cube( void );
~Cube( void );
void anotherFunc( void );
Geometry *mGeometry;
};
Let’s say, in anotherFunc, we’re trying to do the following:
GLushort *indeces = new GLushort;
*indeces = ( *mGeometry ).mFaces[ 0 ];
Error(s)
error: cannot convert ‘QList<short unsigned int>’ to ‘GLushort {aka short unsigned int}’ in assignment
So, we try:
*indeces = mGeometry->( *mFaces )[ 0 ]; //which, is originally how I've accessed pointers-to-containers' indexes.
Error(s)
error: expected unqualified-id before ‘(’ token
error: ‘mFaces’ was not declared in this scope
And, of course, the obvious:
*indeces = mGeometry->mFaces[ 0 ];
Error(s)
error: cannot convert ‘QList<short unsigned int>’ to ‘GLushort {aka short unsigned int}’ in assignment
Constructor for Geometry
Geometry::Geometry( void )
: mFaces( new QList< GLushort > )
{
}
Is there anything wrong I’m doing here? If not, what is the correct method to obtain the index of the pointer to mFaces?
Because
mFacesis a pointer, you have to dereferencemGeometrywith->then dereferencemFaceswith*then useQList<>‘soperator[]to get the number:It’s a little weird because
[0]does the same thing as*. Indices on pointer types, such asx[i], follow the formula*(x + i), so you can also do this for the same effect (but don’t):Which is the same as
(*(mFaces + 0))[0], which is exactly the same as(*mFaces)[0].That is also why you got that error
cannot convert ‘QList<short unsigned int>’ to ‘GLushort’when you tried to doBecause
( *mGeometry ).mFaces[ 0 ];(which, again, is equivalent to the above*mGeometry->mFaces) gets you aQList<GLushort>, and you have to use theoperator[]ofQList<>to get your data.And now for something completely unrelated, you misspelled indices 🙂