티스토리 뷰
Algorithm/Debugging Notes
[C++] Cannot jump from switch statement to this case label 오류 해결
ylog 2022. 1. 3. 19:36Xcode로 코딩하다 난데없이 나타난 Cannot jump from switch statement to this case label 오류.
https://en.cppreference.com/w/cpp/language/switch 를 통해 알아보니
라고 한다.
즉 위 case: 문에서 init_statement를 작성한 경우, 아래 case: 문에서 x에대한 초기화 없이 x를 사용하기 때문에 오류가 난다고 이해했다. (잘못되었다면 지적 부탁드립니다.)
그래서
switch(1) {
case 1: int x = 0; // initialization
std::cout << x << '\n';
break;
default: // compilation error: jump to default: would enter the scope of 'x'
// without initializing it
std::cout << "default\n";
break;
}
가 아닌
switch(1) {
case 1: { int x = 0;
std::cout << x << '\n';
break;
} // scope of 'x' ends here
default: std::cout << "default\n"; // no error
break;
}
과 같이 case문 안에 중괄호를 쳐줘야 한다.
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 유즈케이스
- 2023년
- 네트워킹
- Kotlin
- Info.plist
- KeyChain
- 오토레이아웃
- http/1.1
- snapkit
- CollectionView
- Realm
- Autolayout
- XCTest
- BeautifulSoup
- equaltosuperview
- Clean Architecture
- 클린 아키텍처
- swift
- 스위프트
- IntrinsicContentSize
- collectionViewCell
- CRAWL
- UITest
- http/1
- 웹모바일
- 회고
- IOS
- 부스트캠프
- 2024년
- dismiss
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함