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

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -