c++ - Use the functions of a vector objects using a pointer -


1).why did error? correct syntax?

2).is there way write same code without using library "vector"?

#include <vector>  myclass() {     public:         myclass(int x,int y);         void dothis()         {             //something         } }  int main(void) {     std::vector<myclass>*ex_vector = new std::vector<myclass(5,myclass{10,10});     ex_vector[0]->dothis(); //error here     delete []ex_vector; } 

i error:

error: base operand of '->' has non-pointer type 'std::vector<myclass>' 

the correct syntax is

(*ex_vector)[0].dothis(); 

also, should delete ex_vector; , not delete[] ex_vector; since type of new not raw array type.

however, there's reason new std::vector. use plain object.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -