Some theoretical questions!

I'm studying C++ and I am quite a beginner, and I came up with some questions I really need to solve, to learn well and understand even better. I hope someone of you will clarify these!

So:

1) Is the best specialization of a template function the ones that is written as the last one in the namespace of the primary reference?

2) Does an enum class admit implicit conversions to the below type?

3) Could a CATCH clause that receives an object of type DOUBLE, capture a THROW expression of type LONG DOUBLE?

4) Can a THROW expression be an rvalue?
1.) I don't understand the question.
2.) No. This is the primary advantage of scoped enumerations.
3.) No. An exception of type long double will not be matched with a handler that wants a double.
4.) You can throw rvalues; the active exception object is copy-initialized from the expression on the right of the throw keyword.

To answer literally, the throw-expression itself is always a [p]rvalue of type void.
Last edited on
I'm sorry for my inability of expressing myself in the first question, I tried to translate from the Italian, I failed lol.

By the way thank you so much!!

Oh, another fast thing: what if in the question number 3) we exchange DOUBLE with LONG DOUBLE in both parts? That is: "a CATCH clause that receives an object of type LONG DOUBLE doesn't capture a THROW expression of type DOUBLE". True or false?

Thank you again!!
True, it won't be caught. double and long double are different types, not related by inheritance:
1
2
3
4
5
6
7
int main() 
try {
  throw double { 2.0 }; // calls std::terminate()
} 
catch (long double) {
  // exception object of type `double' is not handled
} 

http://coliru.stacked-crooked.com/a/84305de7ce55f2c3
Last edited on
Finally I understood it! Wow thank you so much my dear. With good examples it's so easy to understand!

I know I'm abusing of your patience, but could you take a look at this question too?

http://www.cplusplus.com/forum/beginner/242670/
Topic archived. No new replies allowed.