请大家说说我这个类的设计上有什么问题
/*用来批量存储文件头信息的类*/class CFHeaderData{private: void** Data; int CurIndex; int MaxIndex;public: CFHeaderData(const int MaxIndex); bool AddTag(const int TagVal,const char* TagName); void* GetData();};inline CFHeaderData::CFHeaderData(const int MaxIndex){ this->MaxIndex=MaxIndex; this->CurIndex=0; Data=new void*[MaxIndex];}inline bool CFHeaderData::AddTag(const int TagVal,const char* TagName){ if((MaxIndex-CurIndex)<3) return false; //空间不足,返回假 this->Data[CurIndex]=new int(TagVal); CurIndex++; this->Data[CurIndex]=new char(*TagName); CurIndex+=2; return true;}inline void* CFHeaderData::GetData(){ return Data;}
void**
[解决办法]
#include <iostream>#include <string>#include <vector>using namespace std;template <class type>class CHeadData{ public: //CHeadData(); CHeadData(int val, const string &name, const type &reserved) { this->val = val; this->name = name; this->reserved = reserved; //"type" need to override = operator } CHeadData(const CHeadData &data) { this->value = data.value; this->name = data.name; this->reserved = data.reserved; } ~CHeadData(){} int GetVal() const {return this->val;} const string& GetName() const {return this->name; } const type& GetReserved() const {return this->reserved;} private: int val; string name; type reserved;};int main(){ vector< CHeadData<string>* > data; CHeadData<string> *test = new CHeadData<string>(1, "test", "test"); data.push_back(test);}