Answer the question
In order to leave comments, you need to log in
How to use the class vector?
There is a class with methods sortByField and search, sort and look for values in the vector of users, respectively.
class User
{
public:
void sortByField(vector<User>& arr, int field);
void search(vector<User>& arr, int field, string str);
...
private:
string fullName;
string birthDate;
...
Answer the question
In order to leave comments, you need to log in
Well, only such methods should not belong to the user class. It would be better to create a new class like Database which is used to store users. And this class can have methods like find or sort. Only the signature of these methods already of course does not contain any vectors: the vector is an implementation detail in this case, which can be changed later.
As I understand it, functions should work with user data (i.e. vector<User>& arr
). So you need to take it out as a field and it is advisable not to forget about adding a new parameter to the class initialization. Well, otherwise, if these functions simply sort vectors or whatever, then remove them from the class.
class UserVector : public std::vector<User>
{
typedef std::vector<User> ParentT;
public:
UserVector& sort(int field);
ParentT::size_type find(int field, const std::string& request);
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question