C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

catch by reference and private conversion operator

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Nicola Musatti
Guest





PostPosted: Fri Mar 03, 2006 5:39 pm    Post subject: catch by reference and private conversion operator Reply with 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?

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





PostPosted: Sun Mar 05, 2006 2:06 am    Post subject: Re: catch by reference and private conversion operator Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.