Как получить доступ к std::variant с помощью std::get, указав информацию о типе во время выполнения. Ниже приведен нерабочий код, который я пробовал
#include
#include
#include
class A {
public:
A(const int a) {
va = a;
// below line doesn't compile
// variant_type = int;
}
A(const std::string& a) {
va = a;
// below line doesn't compile
// variant_type = std::string;
}
// type variant_type;
// above line doesn't compile
std::variant va{};
};
int main() {
std::variant va{"abcd"};
std::cout
Подробнее здесь: https://stackoverflow.com/questions/789 ... riant-data