C# rots your C++ brain part 2
-
class MyException : std::exception {
...
}try {
throw MyException();
} catch(std::exception& ex) {
}The exception is not going to be caught. Can you figure out why?
I admit I didn't spot the missing public modifier, but I noticed something else that I wasn't sure of:
throw MyException**()**;
In C++, you don't use parenthesis when instanciating an object with the default constructor (ie,throw MyException;
). I'm trying to remember if using parenthesis in this case would trigger an unintended call to the copy constructor. Do you know?ShamWow
-
I admit I didn't spot the missing public modifier, but I noticed something else that I wasn't sure of:
throw MyException**()**;
In C++, you don't use parenthesis when instanciating an object with the default constructor (ie,throw MyException;
). I'm trying to remember if using parenthesis in this case would trigger an unintended call to the copy constructor. Do you know?ShamWow
It does not matter if you use the parenthesis or not, the default constructor is called anyway. I tend to use parenthesis (how the hell do you pluralize that word? :)), because it makes the syntax more uniform. There are some odd scenarios though, where the parenthesis can fool the compiler into believing that you're declaring a function prototype. Can't remember exactly how to provoke it though...
-- Kein Mitleid Für Die Mehrheit