【发布时间】:2013-05-26 11:09:36
【问题描述】:
我需要给类内的矩阵一个大小,但是编译器会抱怨const int size。有什么优雅的方式可以满足我的需求?
header.h
class ChessBoard {
int matrix[<size>][<size>];
public:
ChessBoard(int s): <size>(s) {}
};
main.cpp
#include "header.h"
#include <iostream>
int main() {
std::cout << "Enter the size of the chessboard: ";
int n;
std::cin >> n;
ChessBoard cb(n);
return 0;
}
【问题讨论】: