문자열 연산자 < <과 비트 시프 팅 연산자 < <을 한 행에 사용합니다. 약간 혼란 스럽습니다. 왜 코드 A)는 코드 B)와 동일한 출력을 생성하지 않습니까?연산자 << : std :: cout << i << (i << 1);
A)
int i = 4;
std::cout << i << " " << (i << 1) << std::endl; //4 8
B)
myint m = 4;
std::cout << m << " " << (m << 1) << std::endl; //8 8
클래스 민트 : 사전에
class myint {
int i;
public:
myint(int ii) {
i = ii;
}
inline myint operator <<(int n){
i = i << n;
return *this;
}
inline operator int(){
return i;
}
};
감사
아차
거의 중복의 : http://stackoverflow.com/questions/2603312/the-result-of-int-c0-를 coutcc /. 대부분의 실제적인 목적을 위해 비록 수정을 한 연산자로 "<<"대신에 "++"를 사용 했음에도 불구하고 동일합니다 –
@Jerry Coffin : 그들은 매우 유사하지만 전체 << << 대 < <혼돈과 <<가 통상적으로 인수를 변경하지 않는다는 사실 –