Hello
Is there a way to perform mathematical operations with the following custom datatype:
Error:Code:#include <iostream> #include <string> #include <vector> #include <boost/variant.hpp> #include <boost/lexical_cast.hpp> using namespace std; typedef boost::variant< int, string > IntStr; int main() { //Pre-operation is legal IntStr a = 1 + 2; //a = 1+2 cout << a; //outputs 3 cout << endl; //Post-operation is illegal IntStr b = 1; //b = 1 cout << b + 2; //outputs error cout << endl; }
no match for 'operator+' in 'b + 2'
Note:
candidates are: std::_Bit_iterator std:: operator+(ptrdiff_t, const std::_Bit_iterator&)
std::_Bit_const_iterator std:: operator+(ptrdiff_t, const std::_Bit_const_iterator&)
Thanks