C++里打算实现 一个类FileList ,类里放了一个链表存放20个文件的信息,现在想通过重载运算符[] 即对象+下表实现返回每个节点的文件名指针,但看不出那里出错了,程序运行不显示
代码如下:
template<typename T>
struct Node{
T data;
Node* next;
};
typedef struct File_Info{
char file_name[Max_Number];
char file_path[Max_Number];
long size=-1L;
char create_time[General_Volume];
}File_Info;
class FileList{
private:
int filenumber;
Node<File_Info>* first;
public:
string operator[](int& no);
void Print_FileList();
Node<File_Info>* Get_FirstNode();
FileList(char* filepath);
void Insert_ListHead(void* data);
int filecount();
void Find_File(char* filepath);
};
string FileList::operator[](int& no){
Node<File_Info>* each=this->first;
for(int i=0;i<no&&each!=NULL;i++){
each=each->next;
}
string file_name=each->data.file_name;
return file_name;
}
int main(){
FileList* filelist=new FileList("D://Code/C++/temp/*.*");
for(int i=0;i<FileList->filecount();i++){
cout<<filelist[i]<<endl;
}
delete man;
return 0;
}