【发布时间】:2014-02-22 19:47:49
【问题描述】:
我收到编译错误,因为我无法正确地将类成员变量指定为指向二维数组的指针。该板有许多接收指向 2D 数组的指针的示例,但在每种情况下,指针都会立即用于访问数组中的数据,这不是我正在做的。我想保存指向 2D 数组的指针,以便在类中通用。我无法确定正确的演员表。
无论我尝试什么,我都会收到这样的错误。 错误 C2440:“类型转换”:无法从 ... 转换为 ...
此外,我无法将成员变量分配给 NULL。
我正在使用 MS VC++ 2008 Express。
这是我的简化代码:
int _tmain(int argc, _TCHAR* argv[])
{
int _2D[2][3] = { {1,2,3}, {11,22,33} };
return 0;
}
class C
{
public:
C(int* _2dIn[3]) { // <- I don't know how to cast this properly.
init();
m_p2d = (int *[3])_2dIn; // <- The casting error always points to this line.
}
~C(void);
void init(void) {
m_p2d = NULL; // <- This is my second problem.
}
private:
int* m_p2d[3]; // <- And I don't know how to specify this either.
};
【问题讨论】:
标签: c++ arrays pointers casting