История изменений
Исправление i-rinat, (текущая версия) :
Список чего?
Ну вот пример «классического» подхода:
Condiment* milk = new Milk();
Condiment* sugarMilk = new Sugar(milk);
Condiment* doubleSugarMilk = new Sugar(sugarMilk);
cout << "Condiments: " << doubleSugarMilk->description() << '\n';
cout << "Price: " << doubleSugarMilk->price() << '\n';
в нём рецепт задаётся один раз.
А вот вариант с bind'ом:
Condiment condiments;
condiments.description = bind(&accu<string>, &Milk::description, condiments.description);
condiments.description = bind(&accu<string>, &Sugar::description, condiments.description);
condiments.description = bind(&accu<string>, &Sugar::description, condiments.description);
condiments.price = bind(&accu<float>, &Milk::price, condiments.price);
condiments.price = bind(&accu<float>, &Sugar::price, condiments.price);
condiments.price = bind(&accu<float>, &Sugar::price, condiments.price);
cout << "Condiments: " << condiments.description() << '\n';
cout << "Price: " << condiments.price() << '\n';
в нём последовательность Milk, Sugar, Sugar надо повторить дважды.
Исходная версия i-rinat, :
Список чего?
Ну вот пример «классического» подхода:
Condiment* milk = new MilkO;
Condiment* sugarMilk = new Sugar(milk);
Condiment* doubleSugarMilk = new Sugar(sugarMilk);
cout << "Condiments: " << doubleSugarMilk->description() << '\n';
cout << "Price: " << doubleSugarMilk->price() << '\n';
в нём рецепт задаётся один раз.
А вот вариант с bind'ом:
Condiment condiments;
condiments.description = bind(&accu<string>, &Milk::description, condiments.description);
condiments.description = bind(&accu<string>, &Sugar::description, condiments.description);
condiments.description = bind(&accu<string>, &Sugar::description, condiments.description);
condiments.price = bind(&accu<float>, &Milk::price, condiments.price);
condiments.price = bind(&accu<float>, &Sugar::price, condiments.price);
condiments.price = bind(&accu<float>, &Sugar::price, condiments.price);
cout << "Condiments: " << condiments.description() << '\n';
cout << "Price: " << condiments.price() << '\n';
в нём последовательность Milk, Sugar, Sugar надо повторить дважды.