so I need to use a template class as a container, so I need to create a new associative container that's derived from STL set, so far this is what I have (Code Snippets from relevant parts).
In UpdatableSet.h
#include <set>
template <class T>
class UpdatableSet : public std::set<T>
{
public:
UpdatableSet(){};
~UpdatableSet(){};
bool add(T);
private:
std::set<T> set;
};
add(T), this method is supposed to add the T to the set and if it was successful, return true, or return false, not sure if this is correct or not, because I don't fully understand the concepts.
template <class T>
bool UpdatableSet<T>::add(T update)
{
if(set.insert(update).good())
{
return true;
}
else
return false;
}
in main
UpdatableSet<CDAlbum> updatableAlbumSet; //Want this to be a set of objects of the CDAlbum kind
updatableAlbumSet.add(theCDAlbum); //how do I use this to add to the set?
Ultimately I'm getting this compilation error
symbol in file bool UpdatableSet::add(CDAlbum) task2Main.o ld: fatal: symbol referencing errors. No output written to a.out
EDIT: So you guys were right, I've figured out that I've needed to create the methods myself instead of deriving it from set.
here's how it looks now
in UpdatableSet.h
template <class T>
class UpdatableSet
{
public:
UpdatableSet(){};
~UpdatableSet(){};
bool add(T);
int size();
int begin();
int end();
typedef typename set<T>::iterator iterator;
private:
std::set<T> set;
};
template <class T>
bool UpdatableSet<T>::add(T update)
{
return set.insert(update).second;
}
template <class T>
int UpdatableSet<T>::size()
{
return set.size();
}
template <class T>
int UpdatableSet<T>::begin()
{
return set.begin();
}
template <class T>
int UpdatableSet<T>::end()
{
return set.end();
}
However I'm getting this error now "task2Main.cpp", line 67: Error: Cannot use int to initialize __rwstd::__rb_tree, std::less, std::allocator>::const_iterator.
"task2Main.cpp", line 67: Error: The operation "__rwstd::__rb_tree, std::less, std::allocator>::const_iterator != int" is illegal.