#ifndef NAME_H
#define NAME_H
#include <string> // For string class
class Name
{
private:
std::string first{};
std::string second{};
public:
Name(const std::string& name1, const std::string& name2) : first(name1), second(name2){}
Name()=default;
std::string get_first() const {return first;}
std::string get_second() const { return second; }
friend std::istream& operator>>(std::istream& in, Name& name);
friend std::ostream& operator<<(std::ostream& out, const Name& name);
};
// Stream input for Name objects
inline std::istream& operator>>(std::istream& in, Name& name)
{
return in >> name.first >> name.second;
}
// Stream output for Name objects
inline std::ostream& operator<<(std::ostream& out, const Name& name)
{
//My error is here while I am adding " " in the overload
return out << name.first << " " << name.second;
}
// Я хотел перегружать < < оператор станд :: ostream, который принимает объект Name в моей правой руки параметра // Теперь, когда я добавил «» в перегрузке .. он представляет меня с ошибкойОшибка при перегрузке оператора (ошибка: не подходит для «оператора <<» (типы операндов не являются «станд :: basic_ostream <char>» и «Const символ [2]»)
// ошибка выглядит следующим образом: ошибка: нет соответствия для 'operator < <' (типы операндов: 'std :: basic_ostream' и 'const char [2]') return out < < name.first < < "" < < name.second; ^
В сообщении об ошибке содержится много полезной информации. – juanchopanza
Что значит u? –
Я имею в виду, прочитав сообщение об ошибке, посмотрю на ваш код и выясню его. Или, если вы хотите получить помощь, опубликуйте [mcve] и объясните, с чем вы столкнулись. – juanchopanza