Код: Выделить всё
GreggsМетод makeOrder должен установить значение в кортеже колбасы_roll, зная его тип на основе варианта варианта в этом конкретном индексе. Этот метод должен быть доступен во время выполнения.
Код: Выделить всё
#include
#include
#include
#include
#include
template
class Greggs {
public:
constexpr Greggs(AllArgs... args) : flavours({args...}) {}
bool makeOrder(std::string order, size_t index) {
if (index >= this->flavours.size())
return false;
const std::variant flavour = this->flavours[index];
if (flavour.index() == 0) { // Checks if the variant is int
int value = std::stoi(order);
this->setSausageRollArg(index, value);
}
else {
this->setSausageRollArg(index, order);
}
return true;
}
private:
template
void printOrder(T value) const {
std::cout makeOrder("73", 0);
return 0;
}
Код: Выделить всё
main.cpp:36:59: error: assigning to 'typename tuple_element::type' (aka 'int') from incompatible type 'std::string'
36 | if (index == 0) std::get(this->sausage_roll) = value; // Sets the tuple arg
Код: Выделить всё
Sausage roll contains Vegan onions
Sausage roll contains 1 onions
Sausage roll contains 73 onions
Подробнее здесь: https://stackoverflow.com/questions/798 ... stdvariant
Мобильная версия