I have a class template in C++ and another class that inherits it. The latter is not a class template, as you will see. The problem appears when I try to define the constructor of the derived class, by calling the constructor of the base class (the template one). I've posted the error below the code.
For simplicity's sake, I've only added the declarations. If you feel the code might help you get an idea of what the problem might be, I'll gladly post it.
state2d.h
#ifndef STATE2D_H
#define STATE2D_H
template <typename T>
class State2D
{
public:
State2D(unsigned int _rows, unsigned int _columns);
State2D(unsigned int _rows, unsigned int _columns, const T& val);
State2D(const State2D<T> &st);
~State2D();
T& operator()(unsigned int i, unsigned int j);
const T& operator()(unsigned int i, unsigned int j) const;
unsigned int GetRowCount() const;
unsigned int GetColumnCount() const;
unsigned int GetAvailablePositionsCount() const;
protected:
T** matrix;
unsigned int rows;
unsigned int columns;
unsigned int availablePositions;
};
#endif // STATE2D_H
TicTacToeState.h
#ifndef TICTACTOESTATE_H
#define TICTACTOESTATE_H
#include "state2d.h"
class TicTacToeState : public State2D<char>
{
public:
TicTacToeState();
};
#endif // TICTACTOESTATE_H
TicTacToeState.cpp
#include "tictactoestate.h"
TicTacToeState::TicTacToeState() : State2D(3,3,' ') // ERROR here; see below
{
}
error: class 'TicTacToeState' does not have any field named 'State2D' error: no matching function for call to 'State2D::State2D()' candidates are: State2D::State2D(const State2D&) [with T = char] State2D::State2D(unsigned int, unsigned int, const T&) [with T = char] State2D::State2D(unsigned int, unsigned int) [with T = char]
Any ideas?