CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Lookup rule

  1. #1
    Join Date
    Jun 2006
    Location
    Chile
    Posts
    13

    Arrow Lookup rule

    Given a program as simple as

    class A{void func();}
    class Bublic A{void func();}
    class Cublic B,A{void func();}


    // call it
    C p;
    p.func();

    How can a compiler determine which function is called ? Thank you.

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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.

  3. #3
    Join Date
    Jun 2010
    Posts
    115

    Re: Lookup rule

    Besides, if your base class is virtual, it will use the virtual class first before checking itself.

  4. #4
    Join Date
    Dec 2009
    Posts
    145

    Re: Lookup rule

    Quote Originally Posted by Maejie View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured