Однако, если я правильно понимаю, в стандарте C++ такого требования нет. Итак, я придумал головоломку:
Код: Выделить всё
#include
struct Chicken;
struct Egg;
// FYI: You can add any member functions / data members you want to this class.
struct Chicken
{
const Egg& egg;
};
// FYI: You can add any member functions / data members you want to this class.
struct Egg
{
const Chicken& chicken;
};
// DO NOT MODIFY.
bool testChickenAndEgg(const Chicken& chicken, const Egg& egg)
{
return (std::addressof(chicken.egg) == std::addressof(egg)) &&
(std::addressof(chicken) == std::addressof(egg.chicken));
}
// Puzzle: construct such objects chicken (of type Chicken) and egg (of type Egg)
// that testChickenAndEgg(chicken, egg) == true.
// Rules:
// 1. Removing/commenting out existing code is not allowed.
// 2. Overloading testChickenAndEgg is not allowed.
// 3. Non-standard code / undefined behavior is not allowed.
Решение:
Подробнее здесь: https://stackoverflow.com/questions/797 ... uzzle-in-c
Мобильная версия