I don't have many experience with templates, but I'm trying to learn on the go, so could someone please tell me what do I do to make this work, because I have seen a lot of examples of using typenames and explicit instantion and explicit specialization but they just include the basic types like int,char,... So please help because I don't understand what to do.
Container.h
#ifndef CONTAINER_H #define CONTAINER_H template <typename E> class Container { private: E element; public: Container(E pElement); virtual ~Container(); }; #endif // CONTAINER_H Container.cpp
#include "Container.h" #include "Piece.h" template class Container<Piece>; template <typename E> Container<E>::Container(E pElement) //Error Here; { element=pElement; } Piece.h
#ifndef PIECE_H #define PIECE_H #include <iostream> #include <string> using namespace std; class Piece { private: int x; int y; string z; public: Piece(int pX,int pY, string pZ); virtual ~Piece(); }; #endif // PIECE_H Piece.cpp
#include "Piece.h" Piece::Piece(int pX, int pY, string pZ){ x=pX; y=pY; z=pZ; } And the error I'm getting is this:
src\Container.cpp|7|error: no matching function for call to 'Piece::Piece()'| src\Container.cpp|7|note: candidates are:| src\Piece.cpp|3|note: Piece::Piece(int, int, std::string)| src\Piece.cpp|3|note: candidate expects 3 arguments, 0 provided| include\Piece.h|8|note: Piece::Piece(const Piece&)| include\Piece.h|8|note: Piece::Piece(const Piece&)| And I don't know what I'm supposed to do there to make things work. Please help.
using namespace std;in a header file.