Программы на C++. Форум разработчиков
Anonymous
Функция продолжает возвращать моностатную переменную std::variant (тип, не найденный в параметрах альтернативного типа,
Сообщение
Anonymous » 29 дек 2024, 13:07
Итак, по сути, я наткнулся на проблему с одной из реализаций моего класса на C++, вот функции, из-за которых эта проблема возникает.
Interpreter.cpp:
Код: Выделить всё
using T = variant;
double Interpreter::negateDouble(T value) const {
return visit([](const auto& right) -> double {
if constexpr (is_same_v){
return -right;
}
throw runtime_error("Operand must be numbers.");
}, value);
}
string Interpreter::NormalizeDouble(const string& txt) const {
string strBuilder = "";
bool atDot = false;
bool isAllZeros = false;
bool isDecimal = false;
for(const char& c : txt) {
if(c == '.') {
atDot = true;
}
if(!atDot) {
strBuilder += c;
} else {
if(c == '0') isAllZeros = true;
else if((c >= '0' && c string {
if constexpr (is_same_v){
return val;
} else if constexpr (is_same_v) {
return val ? "true" : "false";
} else if constexpr (is_same_v) {
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79315372/function-keeps-returning-a-monostate-stdvariant-variable-a-type-not-found-wit[/url]
1735466825
Anonymous
Итак, по сути, я наткнулся на проблему с одной из реализаций моего класса на C++, вот функции, из-за которых эта проблема возникает. Interpreter.cpp: [code] using T = variant; double Interpreter::negateDouble(T value) const { return visit([](const auto& right) -> double { if constexpr (is_same_v){ return -right; } throw runtime_error("Operand must be numbers."); }, value); } string Interpreter::NormalizeDouble(const string& txt) const { string strBuilder = ""; bool atDot = false; bool isAllZeros = false; bool isDecimal = false; for(const char& c : txt) { if(c == '.') { atDot = true; } if(!atDot) { strBuilder += c; } else { if(c == '0') isAllZeros = true; else if((c >= '0' && c string { if constexpr (is_same_v){ return val; } else if constexpr (is_same_v) { return val ? "true" : "false"; } else if constexpr (is_same_v) { cout Подробнее здесь: [url]https://stackoverflow.com/questions/79315372/function-keeps-returning-a-monostate-stdvariant-variable-a-type-not-found-wit[/url]