1

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;
};
2
  • 2
    Shouldn't it be m_a.data<T>();?
    – Asha
    Mar 19, 2012 at 8:34
  • This code alone does not generate compiler error (at least in Visual Studio 2010, but I think it will not generate an error in any conforming compiler). To show the error you should actually call the B::data function somewhere. For example in main add a variable of B and call data on it... Mar 19, 2012 at 8:46

1 Answer 1

0

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).

1
  • 1
    When I woke up this morning I knew what the problem was right of the bat. This was just one of those times I was working way too many hours and started made a really stupid mistake. I just wish it wasn't on such a easy problem because I knew better.
    – Richard
    Mar 19, 2012 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.