【发布时间】:2012-01-20 20:20:12
【问题描述】:
这个对我来说有点奇怪。
我有一个指向类成员 (mGeometry) 的指针,而该类成员又持有指向 QList< GLushort > 数据成员 (mFaces) 的指针。我正在尝试通过 Cube 类获取 mFaces 的索引。
因此,更简化的版本如下所示:
struct Geometry
{
Geometry( void );
~Geometry( void );
void someFunc( void );
QList< GLushort > *mFaces;
};
class Cube
{
public:
Cube( void );
~Cube( void );
void anotherFunc( void );
Geometry *mGeometry;
};
假设在anotherFunc,我们正在尝试执行以下操作:
GLushort *indeces = new GLushort;
*indeces = ( *mGeometry ).mFaces[ 0 ];
错误
error: cannot convert ‘QList<short unsigned int>’ to ‘GLushort {aka short unsigned int}’ in assignment
所以,我们尝试:
*indeces = mGeometry->( *mFaces )[ 0 ]; //which, is originally how I've accessed pointers-to-containers' indexes.
错误
error: expected unqualified-id before ‘(’ token
error: ‘mFaces’ was not declared in this scope
当然还有显而易见的:
*indeces = mGeometry->mFaces[ 0 ];
错误
error: cannot convert ‘QList<short unsigned int>’ to ‘GLushort {aka short unsigned int}’ in assignment
几何构造函数
Geometry::Geometry( void )
: mFaces( new QList< GLushort > )
{
}
我在这里做错了什么吗?如果不是,那么获取指向mFaces的指针的索引的正确方法是什么?
【问题讨论】:
标签: c++ arrays qt pointers indexing