default-initialization

How to let a variable be dependent on other variables inside a class?

天涯浪子 提交于 2021-01-27 04:48:23
问题 What is wrong with the variable international_standard_book_number ? How can I make it that it changes, whenever isbn_field_i changes? #include <iostream> #include <string> class ISBN { private: unsigned int isbn_field_1 = 0; unsigned int isbn_field_2 = 0; unsigned int isbn_field_3 = 0; char digit_or_letter = 'a'; std::string international_standard_book_number = std::to_string(isbn_field_1) + "-" + std::to_string(isbn_field_2) + "-" + std::to_string(isbn_field_3) + "-" + digit_or_letter;