Answer the question
In order to leave comments, you need to log in
How to make a method to add an element to an array of a class?
Class header:
typedef struct {
char firstname[30];
char lastname[30];
} WriterData;
class Writers {
public:
Writers();
~Writers();
void getWriters(const Writers&);
void insertWriter(char* firstname_writer, char* lastname_writer);
private:
WriterData* writers;
unsigned int count;
};
Answer the question
In order to leave comments, you need to log in
1) Forget about char*/char[] in your task, it's superfluous. There is std::string.
2) WriterData -> Writer. And it's better to just write struct Writer {};
3) The data must be stored in a std::vector (or other container, this issue should be discussed separately), then the count variable is not needed. It should probably be a std::shared_ptr vector.
4) getWriters -> writers, and it should return a vector without taking any arguments and be a const method. Another question is whether this method is needed at all.
5) insertWriter -> addWriter, again accept two std::string const&. It is also possible to return a std::shared_ptr with a newly created writer, which is optional, see the problem.
PS In general, devaloneadvised you to move in the right direction, i.e. to read books on C++ and docks.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question