#include <vector>
#include <list>
#include <string>
template <class Type>
class Base {
protected:
std::string line;
public:
Base();
//Type histories [2];
std::string DisplayHistory();
std::string DisplayRecent();
};
class DerivedA : public Base<T> {
//error: 'T' was not declared in this scope
//error: template argument 1 is invalid
protected:
std::string last;
std::string combined;
std::list<std::string> A;
public:
DerivedA();
void Add(std::string line);
std::string DisplayHistory();
};
class DerivedB : public Base<T> {
protected:
std::string last;
std::string combined;
std::vector<std::string> B;
public:
DerivedB();
void Add(std::string line);
std::string DisplayHistory();
};
template <class T>
Base<T>::Base()
{
histories[0] = DerivedA();
histories[1] = DerivedB();
}
template <class T>
std::string Base<T>::DisplayHistory()
{
return histories[0].DisplayHistory() + "\n" + histories[1].DisplayHistory();
}
template <class T>
std::string Base<T>::DisplayRecent()
{
return last;
}
DerivedA::DerivedA()
{
combined = "List History:\n";
}
void DerivedA::Add(std::string line)
{
if (A.size() <= 50)
{
A.push_front(line);
}
else
{
A.pop_back();
A.push_front(line);
}
last = line;
}
std::string DerivedA::DisplayHistory()
{
for (int n = A.size(); n > 0; n--)
{
combined.append(A[n]);
combined.append("\n");
}
return combined;
}
DerivedB::DerivedB()
{
combined = "STD:Vector List History:\n"
}
void DerivedB::Add(std::string line)
{
if (B.size() <= 50)
{
B.push_front(line);
}
else
{
B.pop_back();
B.push_front(line);
}
last = line;
}
std::string DerivedB::DisplayHistory()
{
for (int n = B.size(); n > 0; n--)
{
combined.append(B[n]);
combined.append("\n");
}
return combined;
}