Error while trying to use the boost::variant – "No matching function for call"

  boost, boost-variant, c++, variant

I’m continuously getting errors saying "No matching call for function" while using boost::variant.
Below is my code snippet.

struct Output {
    int a;
    float b;
}
    
typedef boost::variant<ClassA<X, Y>, ClassA<>> ClassAGeneric;

class Operation: public boost::static_visitor<Output>
{
public:
    double d;
    int a;
    float b;
    
    Output operator()(ClassA<X, Y> obj) const
    {
        obj.operate(d, a, b);
        return (Output) {a, b};
    }
    
    Output operator()(ClassA<> obj) const
    {
        obj.operate(d, a, b);
        return (Output) {a, b};
    }
};

I’m getting this error in the obj.operate() call in the first operator() that is defined.

I tried the passing the templates as well like mentioned in the other answer, but I still see an error.

obj.operate<X,Y>(d,a,b);

Could somebody help me with this?

Source: Windows Questions C++

LEAVE A COMMENT