声明一个在头文件中返回2D数组的函数?

min*_*cho 1 c++ arrays declaration header-files

我试图在我的头文件中声明一个返回2D数组的函数.考虑到我们已经知道阵列的大小,怎么能实现呢?以下是我目前正在做的事情.

class Sample
{
public:
    char[x][y] getArr();
    void blah(int x, int y);
private:
    const static int x = 8;
    const static int y = 2;
    char arr[x][y];
};
Run Code Online (Sandbox Code Playgroud)

Ind*_*ant 7

我认为你应该使用typedef.

    typedef char TArray[2][2];
    TArray& getArr();
Run Code Online (Sandbox Code Playgroud)


Kar*_*tel 5

数组不是C++中的一等公民.请改用boost::array(或std::array在C++ 0x中).它会表现得更像你希望它的表现.