You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Working thru chapter 11 on Smart Pointers. I am not sure why I am getting a different num of instances than the book. I have removed the Catch2 test cases and put all code in main(). I do not get 2 instances at any point of time in the below code, contrary to what the books says. Thanks
C++20 with Visual Studio 2022
`struct DeadMenOfDunharrow {
DeadMenOfDunharrow(const char* m = "")
: message{ m } {
oaths_to_fulfill++;
}
~DeadMenOfDunharrow() {
oaths_to_fulfill--;
}
const char* message;
static int oaths_to_fulfill;
};
int DeadMenOfDunharrow::oaths_to_fulfill{};
void print_number() {
std::cout << "num of instances: " << DeadMenOfDunharrow::oaths_to_fulfill << std::endl;
}
int main()
{
auto aragorn = std::make_unique<DeadMenOfDunharrow>();
auto son_of_arathorn{ std::move(aragorn) };
print_number(); // prints 1
son_of_arathorn = std::make_unique<DeadMenOfDunharrow>();
print_number(); // prints 1, book expects 2 here
son_of_arathorn = std::move(aragorn);
print_number(); // prints 0
}`
The text was updated successfully, but these errors were encountered:
Working thru chapter 11 on Smart Pointers. I am not sure why I am getting a different num of instances than the book. I have removed the Catch2 test cases and put all code in main(). I do not get 2 instances at any point of time in the below code, contrary to what the books says. Thanks
C++20 with Visual Studio 2022
The text was updated successfully, but these errors were encountered: