Question

There are a ton of questions regarding this problem but none of them seem to be a solution to my problem. I don't think this is really a Boost::Variant issue; I'm pretty sure that I'm just using templates in an incorrect manner. I was able to strip down the code so you can compile it and see the problem for yourself, it's pretty simple - I keep getting a 'no function call' error from gcc even though it appears to be right there. I'm probably doing something stupid but I can't seem to see what I'm doing wrong.

#include <boost/variant.hpp>

typedef boost::variant<int, std::string> Data;

struct A
{
    template <typename T> T data() { return boost::get<T>(m_data); };
    private:
      Data m_data;
};

struct B
{
   template <typename T> T data() { return m_a.data(); };
   private:
     A m_a;
};

int main (int argc, char *argv[])
{
    return 0;
};
Was it helpful?

Solution

As Asha noted in a comment you should write:

template <typename T> T data() { return m_a.data<T>(); };

in struct B.

It is needed because template parameters are not deducted automatically based on return type (only based on arguments).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top