Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit conversion vs implicit constructor #431

Open
leonid-s-usov opened this issue Sep 2, 2024 · 1 comment
Open

Implicit conversion vs implicit constructor #431

leonid-s-usov opened this issue Sep 2, 2024 · 1 comment

Comments

@leonid-s-usov
Copy link

Channel

This is a "C++Weekly" episode request.

Topics

Suddenly I got puzzled what happens if class B with an implicit conversion to A is passed as an argument to parameter type A with an implicit constructor from const B&. I was surprised! https://godbolt.org/z/EabPGnY4z

  • gcc compiles and calls the constructor of A(const B&) and ignores the conversion o_0
  • msvc gives a strange error that an "operator could not be called" 🫤
  • llvm detects and reports a conversion ambiguity with the two candidates listed💪💪

Length

This should be bite-sized (5-10 minutes) episode

@Dharmesh946
Copy link

Rules about what conversion chains are considered (or not) in C++ are indeed not always crystal clear. An educational presentation would be appreciated... (along with best-practices).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants