0

I am trying to write a class, which should either define a member function with one or no parameters depending on whether its template type is void or not, as in:

template<typename R = void>
class Query 
{
public:
    // define if R is void
    void Answer()
    {
        ...
    }

    // define if R is NOT void
    void Answer(R&& result)
    {
        ...
    }
};
Alf
  • 752
  • 1
  • 7
  • 13
  • Please show your complete class definition. This is typically done using specialization, but the exact approach depends on many other details, so it's not possible to answer this without a more complete picture of the template. Sometimes it becomes necessary to employ other features of C++, like inheritance, in order to get the desired end results. For more information, open your C++ book to the chapter that explains how to specialize templates, and read it. – Sam Varshavchik Feb 29 '20 at 01:48
  • @jbandes My question was marked as duplicate, but the answer doesn't work for me. Using the example from the other question, e.g: template::value>::type> void Answer(R&& result) { } still produces: error C2182: 'result': illegal use of type 'void' with VS2019 – Alf Feb 29 '20 at 02:03

0 Answers0