I am creating a sorter superclass with subclasses for the specific sorts. I am planning to use a vector called data for all sorts but am wondering why this is giving a syntax error(see the code below)
I have declared a protected member data so it can be accessible by all the subclasses but the compiler does not like it.
template<typename T>
class Sorter{
protected:
vector<T> data;
public:
Sorter();
Sorter(T& x):data(x){}
void setData(const std::vector<T>& x) {
data = x;
}
virtual void sort() = 0;
};
template <typename T>
//bubble sort
class MysterySorterA: public Sorter<T>{
public:
virtual void sort(){
//auto& t1 = this->data[0];
//auto& t2 = this->data[1];
for (unsigned long i = 0; i < data.size()-1; i++)
// Last i elements are already in place
for (unsigned long j = 0; j < data.size() - i - 1; j++)
if (data[j] > data[j+1])
swap(&data[j],&data[j+1]);
/*if(t1 < t2){
cout << "Comparing is OK" << endl;
}*/
cout << "Mystery Sorter A" << endl;
}
void swap(int *x, int *y){
int temp = *x;
*x = *y;
*y = temp;
}
};
I am expecting to see no error messages but I am getting a "use of undeclared identifier" EDIT: "Data" is the undeclared identifier
exact message: "use of undeclared identifier 'data'"