 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Nicola Musatti Guest
|
Posted: Fri Mar 03, 2006 5:39 pm Post subject: catch by reference and private conversion operator |
|
|
Hallo,
In experimenting on the design of an exception that cannot be caught I
wrote the following program:
class A {
operator A& ();
};
int main() {
try {
throw A();
}
catch ( A & a ) {
}
}
I expected it to generate an error, but to my surprise two out of my
three compilers accept this code. Who's right?
Thank you,
Nicola Musatti
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
Alberto Ganesh Barbati Guest
|
Posted: Sun Mar 05, 2006 2:06 am Post subject: Re: catch by reference and private conversion operator |
|
|
Nicola Musatti ha scritto:
| Quote: | Hallo,
In experimenting on the design of an exception that cannot be caught I
wrote the following program:
class A {
operator A& ();
};
int main() {
try {
throw A();
}
catch ( A & a ) {
}
}
I expected it to generate an error, but to my surprise two out of my
three compilers accept this code. Who's right?
|
Why do you expect it to generate an error? I would have said the
opposite, because AFAIK binding an object of type A to an A& is a
"direct binding" and thus it won't involve a call to operator A&().
Moreover 15.3/3 does not consider the presence of conversion operators
when matching handlers to exception objects.
Which compiler gives the error and which error it is?
Ganesh
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|