jeudi 31 octobre 2019

How to use Boost::Variant inside a structure?

ValueType is a boost variant. I am using this as a member of struct1. I want to write + operator overloading for struct1.

  1. Currently I got an error in the below code. Please help me to solve this.

    using ValueType = boost::variant;

    struct struct1 { ValueType value; int length;

    struct1 &operator+(const struct1 &right)
    {
        length = length + right.length;
        value = value + right.value; // ------> error
        return *this;
    }
    

    };

  2. Can I use template structure here? If yes, please add the code with operator overloading.

Aucun commentaire:

Enregistrer un commentaire