괄호로 펑키 한 비즈니스없이 C++에서 일회용 변수를 만들 수 있습니까?C++에 이동 및 삭제 의미가 있습니까?
const float phi = 0;
{
const float _phiTemp = atan2(tan(cluster.beta), tan(cluster.alpha));
float& phiRef = const_cast<float&> phi;
phiRef = HALF_PI - std::abs(HALF_PI - std::abs(std::move(_phiTemp)));
}
// _phiTemp is disposed and phi is a const, and safely used in the calculation
// through std::move()
나는 실종 뭔가 : 여기
const float _phiTemp = atan2(tan(cluster.beta), tan(cluster.alpha));
const float phi = HALF_PI - std::abs(HALF_PI - std::abs(_phiTemp));
// After running this code I want _phiTemp to be unaccessible, and the
// compiler to send an error if I ever try
내가 원하는 무엇의 긴 추한 구현 : 여기에
내가 무엇을 달성하고자하는의 예입니다? C++에서 "즉시"변수 처리가 있습니까?
"C++에는"즉시 "변수 처리가 없습니까? *"예, 이미 그 예를 만들었습니다. 괄호를 사용하여 범위를 나타내며 범위는 수명을 나타냅니다. 그것에 대해 아무것도 못 생겼어. –
글쎄, 순식간에 "현재 범위의 스택에서 변수를 제거하십시오."(+ 컴파일러가 변수가 더 이상 없다는 것을 알 수 있도록). –
'phi'에서 const를 버리고 할당하면 동작이 정의되지 않습니다. – molbdnilo