an interesting function definition

Hello
I've seen a function definition in a program. I've not seen something like that before.I tried it and it really compiles with no error. Here's the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
class Y
{
        public:
                Y(){}
                virtual ~Y(){}
                virtual void f() //this is valid!!!
                try{
                        std::cout<<__func__<<"\n";
                }
                catch(...)
                {
                }
};


the function definition and try block starts at the same point.is this something special? why do you think the programmer did such a thing?

thanks.
Last edited on
xyzt wrote:
is this something special?

Yes. See here -> http://www.drdobbs.com/184401297
Thanks.
That's pretty cool. I had no idea...

__func__ is still nonstandard, though. ;)
closed account (Lv0f92yv)
Quick question - in one of the examples in the Dr.Dobbs article, he does this:

1
2
3
4
5
6
7
8
class C
{
   int &r;
   C(int &n)
   {
       r = n; // won't work!
   }
};


I can't compile this, I get an error:
uninitialized reference member `C::r'

pointing to the int &r;...


Even after removing the line he says won't work, I still get a compiler error. To me, it doesn't make sense to do int &r;... Not sure what I'm looking at there (declaring an address of something that is an integer?).

Thanks to any who can give a clarification.
Last edited on
The comment "won't work" should be on line 3... References must be initialized and are not assignable.
Last edited on
There's no default constructor and those references need initialization and cannot be assigned, ITECIMBS.

EDIT: Dammit.

-Albatross
Last edited on
closed account (Lv0f92yv)
Alright. Making sure I'm not delusional.

Topic archived. No new replies allowed.