I have a template class hierarchy , I have to derived a class from an abstract one that declare :
template<typename T>
virtual T findValue(const std::size_t , const std::size_t ) const noexcept = 0;
But in the derived class my findValue
method have different signature :
template<typename T>
T findValue(const std::size_t i, const std::size_t j,
const std::size_t rBlock, const std::size_t cBlock
) const noexcept ;
So what is the best way to make the derived class not abstract ?
of course I can define :
private:
template<typename T>
T findValue(const std::size_t r, const std::size_t c) const noexcept override
{ return T(0) ; }
but I don't like this ! so what are better ways to doing so and working with derived class (not abstract of course)
EDIT
in all the function above the template <>
is referred to the class not to the method :
template <typename T>
class BlockCompressedMatrix :
public SparseMatrix<T>
{
public:
virtual T& operator()(const std::size_t , const std::size_t) noexcept override = 0 ;
virtual const T& operator()(const std::size_t , const std::size_t) const noexcept override = 0 ;
virtual void print() const noexcept override = 0;
protected:
virtual std::size_t findBlockIndex(const std::size_t, const std::size_t ) const noexcept = 0 ;
virtual T findValue(const std::size_t , const std::size_t ) const noexcept = 0;
};
and the derived is something like this ! (this compile)
# include "BlockCompressedMatrix.H"
namespace mg {
namespace numeric {
namespace algebra {
template <typename T>
class Block
: public BlockCompressedMatrix<T>
{
public:
Block(const std::size_t n)
{
ba_.resize(n);
}
T& operator()(const std::size_t , const std::size_t ) noexcept override ;
const T& operator()(const std::size_t , const std::size_t )const noexcept override ;
void constexpr print() const noexcept override ;
private:
using SparseMatrix<T>::dummy ;
std::vector<T> ba_ ;
std::size_t findBlockIndex(const std::size_t , const std::size_t ) const noexcept override {return 0;} ;
T findValue(const std::size_t , const std::size_t ) const noexcept override {return T(0);} ;
};
template <typename T>
T& Block<T>::operator()(const std::size_t i, const std::size_t j) noexcept {
dummy = ba_[0];
return dummy ;
}
template <typename T>
const T& Block<T>::operator()(const std::size_t i, const std::size_t j)const noexcept {
dummy = ba_[0];
return dummy ;
}
template <typename T>
void constexpr Block<T>::print() const noexcept
{
std::cout << "Hello !" << std::endl;
}