c++的template clsaa的问题:源程序有什么错误?清指示!
//file *.h
#ifndef CFileT_H
#define CFileT_H
#include <iostream>
#include <fstream>
#include "conio.h"
using std::cout;
using std::cin;
using std::endl;
const int FILENAMEMAXLEN =20;
template< class DATA_T
class CFileT
{public:
CFileT(char * = "Mydata.dat");
bool InitRead( void );
bool InitWrite( void
void CloseRead();
void CloseWrite();
void WriteData( const DATA_T out_data
void ReadData( DATA_T &in_data );
int GetStatus();
~CFileT();
private://private member data
char Filename[ FILENAMEMAXLEN ];
// ifstream InFile; //这二行如果不注释掉,会有missing storage-class or //type specifiers错误提示,为什么?
// ofstream OutFile; //
int Status;
};
#endif
//file *.cpp
//member function definitions for CFileX class
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
using std::cerr;
#include "CFileT.h"
template< class DATA_T >
CFileT<DATA_T>::CFileT(char* filename)
{
strcpy(Filename, filename);
}
template< class DATA_T >
bool CFileT<DATA_T>::InitRead(void)
{ InFile.open(Filename,ios::in);
if (!InFile)
{cout<<"\n The File Could Not Be Opened.\n\n";
return 0;
}
else return 1;
}
template< class DATA_T >
void CFileT<DATA_T>::CloseRead()
{
if(InFile)
{InFile.close();
}
}
template< class DATA_T >
void CFileT<DATA_T>::ReadData(DATA_T &in_data)
{
if(this->GetStatus())InFile>>in_data
}
template< class DATA_T >
int CFileT<DATA_T>::GetStatus()
{if(!InFile.eof()) Status=1;
else Status=0;
return Status;
}
template< class DATA_T >
bool CFileT<DATA_T>::InitWrite()
{
OutFile.open(Filename,ios::out);
if (!OutFile)
{cout<<"The File Could Not Be Opened.\n";
return 0;
}
else return 1;
}
template< class DATA_T >
void CFileT<DATA_T>::CloseWrite()
{ if(OutFile)
OutFile.close();
}
template< class DATA_T >
void CFileT<DATA_T>::WriteData(const DATA_T out_data)
{
OutFile <<out_data<<"\n";
}
template< class DATA_T >
CFileT<DATA_T>::~CFileT()
{
CloseRead();
CloseWrite();
}
//test.cpp
//this is a test of function for class cfilex as below:
///////////////////////////////////////////////////////
#include <iostream>
#include "CQueue.h"
#include "CFilet.h"
#include "conio.h"
using std::cout;
using std::cin;
using std::endl;
void run_app( void );
void main()
{ run_app();
cout << "finished ";
}
void run_app( void )
{ CFileT <int> myfile;CFileT <int> myfile1;
int trp;
if(!(myfile.InitWrite()))exit(0);
trp=-1;
cout << "Please type the first group data of variable as time,rotation and pulse:\n" ;
cin>>trp;
cout << "Now save the first group data in disk file.\n" ;
myfile.WriteData(trp);
trp=-1L;
cout << "Please type the second group data of variable as time,rotation and pulse:\n" ;
cin>>trp;
cout << "Now save the second group data in disk file.\n" ;
myfile.WriteData(trp);
myfile.CloseWrite();
getch();
cout << "Now read these datas from disk file,and display them as below:\n" ;
trp=-1;
if(!(myfile.InitRead()))exit(0);
while(myfile.GetStatus())
{
myfile.ReadData(trp);
if(myfile.GetStatus())
cout<<trp<<"\n";
}
myfile.CloseRead();
CQueue intQueuex,intQueue1;
int popInteger, i;
cout << "processing the integer list and save it to disk file:\n" << endl;
for ( i = 0; i < 6; i++ ) {
intQueue1.InsertData( i );
}
intQueue1.PrintData();
getch();
if(!(myfile.InitWrite()))exit(0);
trp=-1L;
while ( !intQueue1.isEmpty() )
{
intQueue1.RemoveData( popInteger );
cout << popInteger << " remove from list1.\n" ;
trp=popInteger;
intQueue1.PrintData();
myfile.WriteData(trp);
}
myfile.CloseWrite();
getch();
cout << "Now read these datas from disk file,and display them as below:\n" ;
trp=-1;
if(!(myfile1.InitRead()))exit(0);
while(myfile1.GetStatus())
{
myfile1.ReadData(trp);
if(myfile1.GetStatus())
{
intQueuex.InsertData(trp);
}
}
myfile1.CloseRead();
intQueuex.PrintData();
}
上面程序有什么错误?清指示!//cqueue是类,限于篇幅,就不粘贴了