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

explicit assignment operator #20

Open
Neargye opened this issue Mar 12, 2021 · 1 comment
Open

explicit assignment operator #20

Neargye opened this issue Mar 12, 2021 · 1 comment

Comments

@Neargye
Copy link
Member

Neargye commented Mar 12, 2021

Перенос предложения: голоса +12, -2
Автор идеи: Топунов Владимир Андреевич

Подобно explicit конструктору запрещает неявное преобразование типа при присваивании

std::string s;
s = 49; // Неявное преобразование int в char
std::cout << s << std::endl; // Вывод символа '1' 
class String
{
public:
    explicit operator = (char ch);
...
};

...

String s;
s = 49; // Ошибка компиляции
s = '1'; // OK
@Neargye
Copy link
Member Author

Neargye commented Mar 12, 2021

ldvsoft 9 марта, 11:14
Не придём ли мы к explicit параметрам функций?

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

No branches or pull requests

1 participant