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

Threaded View

  1. #6
    Join Date
    Oct 2008
    Posts
    1,456

    Re: Why g++ fails to find correct overload in this case?

    Quote Originally Posted by ar115 View Post
    but the signatures of foo::write_binary and global write_binary are different
    so the compiler must be able to choose correct function
    the write_binary name in the class declarative scope hides the global write_binary name; in general, the compiler will traverse the "scope tree" from leaf to nodes and it will stop as soon as a node has been fully traversed and a set of candidate names has been found. The actual (function,varaible,whatever) name is picked from that set only.

    For example, in the code

    Code:
    void f(int x);
    
    struct A { void f() { f(1); } };
    at the point of f(1) call there's an "f" name in the class scope. The set of candidates for overload resolution becomes {A::f()}. Therefore a compiler error is raised.

    Indeed, the same thing happens with variables:

    Code:
    class A{ public: A(int x){ x=x; } private: int x; }
    will not set the member variable x to the expected argument value ( but A(int x):x(x){} will do )
    Last edited by superbonzo; April 5th, 2010 at 04:11 AM.

Tags for this Thread

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