There are several problems with your code. The main one is that the Python array area
contains objects of two different types: The first is the integer y
, the second is the array length
. All elements of a C++ array must have the same type.
Depending on what you want to use it for, you can replace the board
array with a std::pair
. This is an object containing two elements of different types.
Also, in C++ arrays with non-constant lengths must be dynamically created. Either using the new
operator or (better) using std::unique_ptr
. (Or you might want to use std::vector
instead.)
Here's a small C++ program that does something like what you want to do:
#include <utility>
#include <memory>
auto createBoard(int x, int y) {
return std::make_pair(y, std::make_unique<int[]>(x));
}
int main() {
auto board = createBoard(5,6);
return 0;
}
(This will only work if your compiler supports C++14 or newer.)
But this is actually rather much above "newbie" level, and I doubt that you will find it very useful.
It would be better to start with a specification of what your program should do, rather than try to translate code from Python.
EDIT
Same code with std::vector
instead of a dynamic array:
#include <utility>
#include <vector>
auto createBoard(int x, int y) {
return std::make_pair(y, std::vector<int>(x));
}
int main() {
auto board = createBoard(5,6);
return 0;
}