New to C++ here. I have a pointer variable type vector
, which I initialized to be n
by m
, where n
and m
are int's given as input. Here is how I initialize it.
std::vector<std::vector<int>>* memo; // This is as a member.
void test(int m, int n) {
memo = new std::vector<std::vector<int>>(m, *new std::vector<int>(n, 0)); // This is inside a method.
}
Later, I try to assign a certain element.
int ans = 5; // In my actual code, it's something else, but I'm just simplifying it.
memo[i][j] = ans; // This gives an error.
I thought I just needed to deference it, because right now it is a pointer type. So I changed it to this:
*memo[i][j] = ans;
However now I got a new error:
C++ no operator matches these operands operand types are: * std::vector<int, std::allocator<int>>
Why isn't this working, and how can I make it work?