Not a duplicate of C++: multidimensional array initialization in constructor since the answers all appear to assume the bounds are known at compile-time.
I'm making a weighted undirected graph class arraygraph
, backed by a 2D array of int
, by the name of edges[][]
. At instantiation time I don't really care what edges[][]
holds; arraygraph
has a method that reads a graph from a given filename and edges
is set to a new int[n][n]
(where n
is the # of nodes in the file) by that function before it populates it.
Trouble is, g++ doesn't seem to like the way I've defined edges[][]
. It wants to have set bounds for the array, and at compile time I don't know the bounds. Should I just redefine edges
as an int *
? Or as edges[][0]
? Or something else entirely?
I'm not a C++ expert by any means (I'm a Python kinda guy) so complex, heavyweight options like the ones in Array with undefined size as Class-member are kinda out of scope (surely there's a simpler way than that...). If what I'm trying to do is a wrong thing entirely than that's also a useful thing to know, and it'd be handy to know what I ought to be doing instead.