Hey, I'm trying to learn C++ templates, i'm also failr new to C++
Could you take a look at this and see if you can see anything i'm missing.
What I'm trying to do is pass a template type to the base class which uses it as a template type as well. Thanks.
// Tile: Key Value Pair | HeaderFile
#ifndef Gard_SX_Comparable
#define Gard_SX_Comparable
namespace SXFramework
{
namespace Collections
{
template <class Type>
class Comparable
{
public:
//Comparable();
virtual int CompareTo(Type comparable) = 0;
};
}
}
#endif
// Tile: Key Value Pair | HeaderFile
#ifndef Gard_SX_KeyValuePair
#define Gard_SX_KeyValuePair
#include "comparable.h"
namespace SXFramework
{
namespace Collections
{
template <class KeyType, class ValueType>
class KeyValuePair : public Comparable<KeyType>
{
public:
// Constructors
KeyValuePair(KeyType key, ValueType value);
// Destructors
~KeyValuePair();
KeyType getKey() const;
ValueType getValue() const;
void setVlaue(ValueType value);
private:
KeyType key;
ValueType value;
};
}
}
#endif
// Tile: Key Value Pair | Code File
#include "KeyValuePair.h"
namespace SXFramework
{
namespace Collections
{
KeyValuePair::KeyValuePair(KeyType key, ValueType value) // <-- Errors
{
this->key = key;
this->value = value;
}
KeyType KeyValuePair::getKey() const
{
return this->key;
}
ValueType KeyValuePair::getValue() const
{
return this->value;
}
void KeyValuePair::setVlaue(ValueType value)
{
this->value = value;
}
int KeyValuePair::CompareTo(KeyValuePair value)
{
if (this > value) return 1;
else if (this < value) return -1;
else return 0;
}
}
}
error C2955: use of class template requires template argument list
error C2955: use of class template requires template argument list
error C2065: 'KeyType' : undeclared identifier
error C2146: syntax error : missing ')' before identifier 'key'
error C2761: KeyValuePair<KeyType,ValueType>::KeyValuePair(KeyType,ValueType)' : member function redeclaration not allowed