0

I want to encapsulate a class which uses template parameter pack and function template into another similar class, like the following example:

#include <iostream>

template<typename ... Args>
struct O2 {

    template<int T>
    void f() {
    }
};


template<typename ... Args>
struct O1 {
O2<Args...> i2;

    template<int T>
    void g() {
        i2.f<T>();
    }
};

int main()
{
    O1<int> i1;
    i1.g<1>();
    return 0;
}

but the compliler it says I'm wrong:

main.cpp: In member function 'void O1<Args>::g()':
main.cpp:18:17: error: expected primary-expression before ')' token
   18 |         i2.f<T>();
      |                 ^
main.cpp: In instantiation of 'void O1<Args>::g() [with int T = 1; Args = {int}]':
main.cpp:25:12:   required from here
main.cpp:18:13: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator<'
   18 |         i2.f<T>();
      |         ~~~~^~

I can't modify the inner class (O2), and I can't use inheritance. Any idea how to do it?

Thx

1 Answers1

1

The correct syntax is:

i2.template f<T>();
Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93