Why is the non-const member function being called, instead of the const one?

If you have two overloads that differ only in their const-ness, then the compiler resolves the call based on whether *this is const or not. In your example code, test is not const, so the non-const overload is called. If you did this: testType test; const testType &test2 = test; test2->x(); you should see that … Read more

Is this change in overload resolution between Clang 3.5 and 3.6 correct or a bug?

I believe Clang is correct to produce this error: The [temp.inst] section of the C++ standard in paragraph 10 says: If a function template or a member function template specialization is used in a way that involves overload resolution, a declaration of the specialization is implicitly instantiated (14.8.3). Forming the implicit conversion sequence necessary to … Read more

Overload resolution looking into namespaces

ADL is not used when explicit template arguments are involved unless you introduce a template function declaration at the call point. You’re using an unqualified form of get using a non-type template argument 0, so you need to introduce a template function declaration or use the qualified version of get as std::get<0>(ar). In standardese [temp.arg.explicit]/8: … Read more

Call of overloaded function taking unsigned int or a pointer is ambiguous when passing integer literal 0

The literal 0 has two meanings in C++. On the one hand, it is an integer with the value 0. On the other hand, it is a null-pointer constant. As your setval function can accept either an int or a char*, the compiler can not decide which overload you meant. The easiest solution is to … Read more

Ambiguous call to overloaded function taking int or float when passing a decimal number

Look at the error message from gcc: a.cpp:16: error: call of overloaded ‘function(double, double)’ is ambiguous a.cpp:3: note: candidates are: void function(int, int) a.cpp:9: note: void function(float, float) A call to either function would require truncation, which is why neither is preferred over the other. I suspect you really want void function(double y,double w). Remember … Read more

Why is a public const member function not called when the non-const one is private?

When you call a.foo();, the compiler goes through overload resolution to find the best function to use. When it builds the overload set it finds void foo() const and void foo() Now, since a is not const, the non-const version is the best match, so the compiler picks void foo(). Then the access restrictions are … Read more

How does the method overload resolution system decide which method to call when a null value is passed?

For the exact rules, see the overload resolution spec. But briefly, it goes like this. First, make a list of all the accessible constructors. public EffectOptions ( params object [ ] options ) public EffectOptions ( IEnumerable<object> options ) public EffectOptions ( string name ) public EffectOptions ( object owner ) public EffectOptions ( int … Read more

Why is template constructor preferred to copy constructor?

As far as I know non-template function is always preferred to template function during overload resolution. This is true, only when the specialization and the non template are exactly the same. This is not the case here though. When you call uct u3(u1) The overload sets gets uct(const uct &) uct(uct &) // from the … Read more