I am trying to add to my class the output operator <<
but in compiling (VS2013) I have a message:
"error C2280:
'std::basic_ostream<char,std::char_traits<char>>::basic_ostream(const
std::basic_ostream<char,std::char_traits<char>> &)' : attempting to
reference a deleted function".
here is my code:
#include "Client.h"
Client::Client(MyString id, MyString full_name, char gender, unsigned short age, unsigned short hobbies_num, char** hobbies_list)
{
this->id = id;
this->full_name = full_name;
if (gender == 'm' || gender == 'M')
this->gender = 'M';
else if (gender == 'f' || gender == 'F')
this->gender = 'F';
else
cout << "wrong gender value" << endl;
if (age >= 18)
this->age = age;
else
cout << "wrong age value" << endl;
this->hobbies_num = hobbies_num;
this->hobbies_list = hobbies_list;
}
Client::Client(const Client& other)
{
this->id = other.id;
this->full_name = other.full_name;
this->gender = other.gender;
this->age = other.age;
this->hobbies_num = other.hobbies_num;
this->hobbies_list = other.hobbies_list;
}
Client::~Client()
{
for (int i = 0; i < hobbies_num; i++) // deleting 2 dimension array
delete[] hobbies_list[i];
delete[] hobbies_list;
}
Client& Client::operator = (const Client& other)
{
if (this->id == other.id) //checks if the client is not the same client
return *this;
else
{
for (int i = 0; i < hobbies_num; i++) // deleting 2 dimension array
delete[] hobbies_list[i];
delete[] hobbies_list;
return Client(other);
}
}
ostream& operator << (ostream& cout, const Client& for_print)
{
return cout << for_print.id << endl
<< for_print.full_name << endl
<< for_print.gender << endl
<< for_print.age << endl
<< for_print.hobbies_num << endl;
}
The message is on the line stating at return cout. here are the prototypes:
#include "MyString.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
class Client
{
MyString id;
MyString full_name;
char gender;
unsigned short age;
unsigned short hobbies_num;
char ** hobbies_list;
public:
Client(MyString, MyString, char, unsigned short, unsigned short, char**);
Client(const Client& other);
~Client(); //dtor
Client& operator = (const Client&); //=
friend ostream& operator << (ostream&, const Client& for_print);
};
I didn't find any solution online. The same command works for me in another class at the same solution.