|
-
August 16th, 2011, 04:23 PM
#1
Lookup rule
Given a program as simple as
class A{void func();}
class B ublic A{void func();}
class C ublic B,A{void func();}
// call it
C p;
p.func();
How can a compiler determine which function is called ? Thank you.
-
August 16th, 2011, 04:43 PM
#2
Re: Lookup rule
The most-derived class (C)'s function will be used in this case.
If C didn't have a func(), then B's would be used.
If C did have a func() but it had a different parameter list, then by default a compile error would result, but a "using B::func" statement in the class definition would allow B's func() to be used.
-
August 16th, 2011, 07:10 PM
#3
Re: Lookup rule
Besides, if your base class is virtual, it will use the virtual class first before checking itself.
-
August 17th, 2011, 06:42 PM
#4
Re: Lookup rule
 Originally Posted by Maejie
Besides, if your base class is virtual, it will use the virtual class first before checking itself.
Eo`eo' eo, unclear enough to qualify your reply. It applies the bottom up approach as a rule (child->parent->grandparent etc)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|