I have a struct called record which contains key, value pair:
struct Record{
char* key=new char();
TYPE value=NULL;
Record(){
key = "default";
value = 10;
}
Record(const char* key_, TYPE value_){
strcpy(key, key_);
value = value_;
}
const Record<TYPE>& operator=(const Record<TYPE>& other){
key = other.key;
value = other.value;
return *this;
}
};
Also, I have a class "SimpleTable" which contains an array of those records:
class SimpleTable:public Table<TYPE>{
struct Record<TYPE> *table;
public:
Problem comes when I try to put date inside those records. My strcpy gives me "Access violation writing location". (All elements of Records array initialized in class constructor):
template <class TYPE>
bool SimpleTable<TYPE>::update(const char* key, const TYPE& value){
for (int i = 0; i < 10; i++){
if (table[i].key == ""){
strcpy(table[i].key , key); // <-------- crash right here
table[i].value = value;
}
}
return true;
}