Подтвердить что ты не робот

Что делает оператор string() {some code}?

У меня есть следующий код в классе:

operator string() {
        return format("CN(%d)", _fd);
}

И хотел знать, что делает этот оператор.

Я знаком с обычными строковыми операторами:

bool operator==(const string& c1, const string& c2);
bool operator!=(const string& c1, const string& c2);
bool operator<(const string& c1, const string& c2);
bool operator>(const string& c1, const string& c2);
bool operator<=(const string& c1, const string& c2);
bool operator>=(const string& c1, const string& c2);
string operator+(const string& s1, const string& s2 );
string operator+(const Char* s, const string& s2 );
string operator+( Char c, const string& s2 );
string operator+( const string& s1, const Char* s );
string operator+( const string& s1, Char c );
string& operator+=(const string& append);
string& operator+=(const Char* append);
string& operator+=(const Char  append);
ostream& operator<<( ostream& os, const string& s );
istream& operator>>( istream& is, string& s );
string& operator=( const string& s );
string& operator=( const Char* s );
string& operator=( Char ch );
Char& operator[]( size_type index );
const Char& operator[]( size_type index ) const;

... но не этот?

4b9b3361

Ответ 2

Это перегрузка оператора преобразования. Класс, который имеет функцию

operator string();

определенный может быть преобразован в строку.

Ответ 3

Если просто вернется представление строки вашего текущего объекта, например. для печати на консоли.

Ответ 5

Казалось бы, это оператор с привязкой к строкам для типа десятичного числа.