How do I write setters and getters for an array? (c++) -


im writing class within c++, not on how create setters , getters arrays (sorry being basic question!) getting following error:

expected primary expression before ']' token

here code:

class planet: public body { private:   string name[];   string star[]; public:   void namesetter (string h_name[])   {       name[] = h_name[];   } }; 

once again sorry such silly question, know not passing index through, however, when create index throws large amount of errors!

string name[]; 

this not array, pointer. use vectors instead:

#include <vector> class planet: public body { private:   vector<string> name;   vector<string> star; public:   void namesetter (const vector<string> &h_name)   {       name = h_name;   } }; 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -