class - (C++)Syntax for instantiating and assigning new objects to 2D vector of pointers to same object type? -
my sincerest apologies if question has been asked, other answers have seen confusing me. have class want use build 2d matrix of type of object. i'm trying write method create new objects, , assign pointers in 2d vector new objects, can't seem syntax right.
i create 2d vector this:
std::vector<std::vector<csinusoid*>> *m_sinematrix; //2d vector of pointers csinusoid objects
and try create method along these lines:
void cwavematrix::init_sinematrix(int x, int y) { m_sinematrix[x][y] = new csinusoid(); }
the line of code inside function i'm having trouble. don't know how tell specific pointer in 2d vector point new object.
note both vector , method private members of same class.
i think problem here:
std::vector<std::vector<csinusoid*>> *m_sinematrix
m_sinematrix isn't 2d vector of csinusoid pointers... it's pointer such vector. , c++ [] operator works on raw pointers vectors. code in function call [x] operator on pointer , treat result 2d vector, call [y] operator on 2d vector , treat result 1d vector. doesn't know how assign csinusoid* vector of csinusoid*s, complains.
to fix this, can either change *m_sinematrix m_sinematrix, or change function (*m_sinematrix)[x][y].
Comments
Post a Comment