need a 2nd pair of eyes for c++ inheritance problem -
22-03-2004
Im workin on a sorting algorithm and I want it to work for any class that inherits from class Sortable. Im using microsoft studio .NET 2003 to compile it. I stripped out all the actual sorting code and left in what was giving me the error. It says that class CharCount cannot be converted into class Sortable and Im wondering why this is the case. Im pretty much stumped as to what the problem is. Its probably something pretty obvious and Id appreciate any help anyone can offer.
here is my header file(main.h):
class Sortable {
public:
Sortable() {};
virtual ~Sortable() {};
public:
virtual int Value() = 0;
};
class CharCount : public Sortable {
public:
CharCount(){character = 0;count = 0;}
virtual ~CharCount() {};
void Init(char theChar) {character = theChar;}
public:
char Character() {return character;}
int Value() {return count;}
void Increment() {count++;}
private:
int count;
char character;
};
this is the c file (main.cpp):
#include "main.h"
void Sort(Sortable **table, int size) {
}
int main() {
CharCount **table = new CharCount *[20];
for(int i = 0; i < 20; i++) {
table[i] = new CharCount();
}
Sort(table, 20); // the compiler finds the error here
//(cannot convert from CharCount** to Sortable**)
return 0;
}
|