나는 클래스에 다음 코드가 있습니다연산자 문자열() (일부 코드)은 무엇을합니까?
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;
...하지만이 하나?
+1은 적절한 이름으로 변환 연산자를 나타냅니다. –
좋은 예제는 타입의 객체가'if (object) {...} else {...}'에서 사용될 수 있도록 해주는'operator bool() {...}'입니다. 컨테이너 유형에서 비어 있지 않은 것이 사실임을 의미하는 것으로 구현 될 수 있습니다. – wich
@wich :'operator bool'은 예상치 못한 동작을 줄 수 있습니다. http://stackoverflow.com/questions/2145931/why-is-operator-bool-invoked-when-i-cast-to-long. – kennytm