Aelian
Aelian

Reputation: 695

How to declare a template method of a template base class using 'using'?

Two methods for accessing template base class members are described here. When the base class member itself is a template, accessing it using the first method (this->) above is described here. Is there a way to use the second method (using xxxx) in this scenario as well?

For example, in the code below, is it possible to replace "????" with something to make the code work?

using namespace std;

template<typename T> class base
{
public:
    template<bool good> void foo()
    {
        cout << "base::foo<" << boolalpha << good << ">()" << endl;
    }
};

template<typename T> class derived : public base<T>
{
public:
    using ????
    void bar()
    {
        foo<true>();
    } 
};

Upvotes: 3

Views: 211

Answers (1)

asimperial
asimperial

Reputation: 46

Just for the record, even though it does not provide any answer or workaround, but I am currently working with VS Express 2013, and I can assure you that

#include <iostream>

template<typename T> class base
{
public:
    template<bool good> void foo()
    {
        std::cout << "base::foo<" << good << ">()" << std::endl;
    }
};

template<typename T> class derived : public base<T>
{
public:

    void bar()
    {
        foo<true>();
    }
};

struct A{};

void main() {

    derived<A> a;
    a.bar();
}

works perfectly fine...

Upvotes: 1

Related Questions