gccvisual-studio-2017c++17template-meta-programmingname-hiding

Name hiding of base member in inherited variadic template


I have the following code that works in VS2017:

template <typename ... Args>
struct Composite: Args...
{
    using Composite<Args...>::foo;
    void foo(float exposure)
    {
        return this->foo(*this, exposure);
    }

    void internalBar(float e)  {  std::cout << "it works" << e;  }
};

it is used in this way:

struct A
{
    template <typename T>
    void foo(T& device, float exposure)
    {
        device.internalBar(exposure);
    }
};

struct B
{};

struct C
{};

int main(int argc, char *argv[])
{
    auto u = Composite<A, B, C>();
    u.foo(5.0f);
    return 0;
}

The problem is with the line using Composite<Args...>::foo because is not in the c++ standard. That's why it does not works with gcc: Composite<Args...> is not a base class of Composite.

I had to use this line because Composite hides the foo of A.

How can i pull in the scope of a single packed parameter?

Thanks.


Solution

  • You can solve lots of problems by adding a level of indirection.

    template <typename ... Args>
    struct CompositeFooWrapper: Args...
    {
    };
        
    template <typename ... Args>
    struct Composite: CompositeFooWrapper<Args...>
    {
        using CompositeFooWrapper<Args...>::foo;
    

    Demo: https://godbolt.org/z/ddsKc3rvx