vendredi 19 janvier 2018

Specializing some methods in partial template especialization

I have a class which has a partial template specialization version. However, the former can't see the method implemented by the generic version. How can I make all methods in the generic version visible by the partially specialized version?

For example:

test.hpp

#include <iostream>

template <typename T>
class A_base{
public:
    virtual void foo() = 0;
};

template <typename T>
class A : public A_base<T> {
public:
    void foo() override {
        std::cout << "foo: generic type" << "\n";
    }
};

template <>
class A<int> : public A_base<int>{
public:
    void bar() {
        std::cout << "bar: int type" << "\n";
    }
};

test.cpp

#include "test.hpp"

int main(){
    A<int> a;
    a.foo(); // expected "foo: generic type"
    a.bar(); // expected "bar: int type"
}

Why A<int> a can't see foo()?

Aucun commentaire:

Enregistrer un commentaire