我遇到了一个基本的数组问题,我似乎无法得到我的头。传递数组到对象方法
我有一个类“StaticDisplayLayer”和构造函数有两个参数 - 一个int和指针的3个无符号整型短的数组:
//constructor definition:
StaticDisplayLayer(int type, unsigned short *displayColor[3]);
//constructor code:
StaticDisplayLayer::StaticDisplayLayer(int type, unsigned short *dColor[3]) : DisplayLayer(type)
{
displayColor = dColor;
}
我试图创建一个类的实例使用以下:
unsigned short layerColor[3] = {(unsigned short)255,(unsigned short)255,(unsigned short)255};
StaticDisplayLayer myLayer(1, &layerColor);
我的理解是,& layerColor是一个指针数组layerColor但编译器是给我下面的错误:
no matching function for call to `StaticDisplayLayer::StaticDisplayLayer(int, short unsigned int (*)[3])'
Candidates are:
StaticDisplayLayer::StaticDisplayLayer(const StaticDisplayLayer&)
StaticDisplayLayer::StaticDisplayLayer(GLenum, short unsigned int**)
我知道第二个候选人是我正在尝试使用的人,但显然我不明白指向数组的指针的概念。如果有人能够阐明如何调用构造函数和/或解释这个的任何资源,我会很感激它 - 到目前为止,我在网上的搜索并没有真正发挥很大的作用。
你有没有考虑过为此使用`std :: vector`?你可以用它来解决所有那些复杂的语法。 – Naveen 2011-12-14 17:47:47
是的,我正要用矢量来重写它,但不想只是让我不明白自己做错了什么。 – TheOx 2011-12-14 17:59:45