code_junkie

Instantiating new object within switch block - why does it fail?

Nov 12th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. switch ([document currentTool]) {
  2. case DrawLine:
  3. NSBezierPath * testPath = [[NSBezierPath alloc]init];
  4. //...rest of code that uses testPath....
  5.  
  6. switch( ... ) {
  7. case A:
  8. MyClass obj( constructor stuff );
  9. // more stuff
  10. // fall through to next case
  11. case B:
  12. // what is the value of obj here? The constructor was never called
  13. ...
  14. }
  15.  
  16. switch( ... ) {
  17. case A: {
  18. MyClass obj( constructor stuff );
  19. // more stuff
  20. // fall through to next case
  21. }
  22. case B:
  23. // obj does not exist here
  24. ...
  25. }
Add Comment
Please, Sign In to add comment