0

I have a problem. I want to initilize my 2Dim array ,which is a member of a class,in the constructor of a class. For example .

class Foo
{
    private:

       bool testArray[100][4];

    public:

       Foo( bool t_array[][4]);         
};

in a Foo.cpp file :

Foo::Foo(bool array[][4])
{
   // initilize it in there with unknown row size 
}

I dont have a specific row size but I know that it will be maximum 100.

How could I initilize my testArray in my constructor? thanks in advance.

4

1 回答 1

1

由于您的类型数组在传递给构造函数时bool [100][4]将衰减为类型指针bool (*) [4],因此您也应该传递行数。这个构造函数没有其他方法可以找出这个数组的实际大小。

或者,您可以考虑std::vector< std::array<bool, 4> >改用。

于 2013-10-12T10:37:59.873 回答