When ı use goto in class in c++ ,I faced to that message,how can ı use goto in class c++?
In member function `void note_system::student_no()':
label 'stop' used but not defined`
When ı use goto in class in c++ ,I faced to that message,how can ı use goto in class c++?
In member function `void note_system::student_no()':
label 'stop' used but not defined`
You would do something like this (to have a single scope exit point, say when for some exotic reason using a RAII-based trick is not possible):
status_code func_with_goto() {
if (i_see_errors()) goto func_end;
...
func_end:
return status_code::error;
}
Or like this (to emulate break-by-label-like behavior):
outer: while (...) {
inner: while (...) {
...
goto outer;
}
}
Or if you just want to reimplement your second Basic
program from 80-th in C++
:
x10: std::cout << "Hello World!" << std::endl;
x20: goto x10;
There are very few cases where goto
may be justified. Its presence complicates static code analysis by both humans and compilers. This does not mean at all that goto
should be banned, it should just be use with double care.