public/Interface.h
#pragma once
template <typename T>
class BaseInterface {
public:
virtual void foo() = 0;
};
private/Base.h
#pragma once
#include "../public/Interface.h"
template <typename T>
class Base : public BaseInterface<T> {
public:
virtual void foo() override;
};
template <typename T>
inline void Base<T>::foo() {
}
main.cpp
#include <iostream>
#include <memory>
#include "public/Interface.h"
int main() {
auto base = std::make_shared< BaseInterface<std::string> >();
base->foo();
return 0;
}
Getting this error:
/usr/include/c++/5/ext/new_allocator.h:120:4: error: invalid new-expression of abstract class type ‘BaseInterface<std::__cxx11::basic_string<char> >’
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
AbstractPureVirtual/public/Interface.h:4:7: note: because the following virtual functions are pure within ‘BaseInterface<std::__cxx11::basic_string<char> >’:
class BaseInterface {
AbstractPureVirtual/public/Interface.h:6:17: note: void BaseInterface<T>::foo() [with T = std::__cxx11::basic_string<char>]
virtual void foo() = 0;
I get this error though I have overridden the pure virtual method in the Derived Class and seems like it is expected as its a template class. If I need to do something similar, how should I go about implementing this?