就像如果我有:通过指向其中一个成员的指针来确定对象指针的最佳方法是什么?
struct S
{
std::size_t szArray;
int dArray[];
} ;
int main()
{
extern int (*pArr)[]; //pointer to member 'dArray' of object with type 'S'
S *pStruct = /*??????????*/; //pointer to the object
}
是什么让这个指针的最佳方式?
你知道数组自然衰变到指向他们第一个元素的指针吗?此外,标准C++不支持结构中的灵活数组,如果在结构中有一个数组,它必须在编译时有一个大小,否则使用['std :: vector'](http://en.cppreference的.com /瓦特/ CPP /容器/载体)。 – 2015-04-03 11:01:21
我知道,但我想使用指向数组的指针,以保留指向多个对象而不是一个对象的信息。无论如何 - 我不知道为什么我留下这样的印象,即C++支持灵活的数组,但在每种情况下都不会改变这种情况。 – AnArrayOfFunctions 2015-04-03 11:25:10