Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help on class interface declaration!!!

Status
Not open for further replies.

zonique

Programmer
Dec 29, 2001
2
MY
Hi all,

i am new to C++, i was trying to declare a class for writing a log file. everyting was fine until i separate interface from implementation! below are the codes :

Log.H
----------------------------------------------
#ifndef LOG_H
#define LOG_H

class Log {
public:
Log ();
~Log();
void appendLog ( string );
void appendLog ( unsigned long );
string readLog ();
void closeFile ();
private:
void openFile ();
ofstream outFile;
};

#endif
----------------------------------------------

Log.cpp
----------------------------------------------
#include <iostream>
using std::cout;
using std::cin;
using std::ios;
using std::cerr;
using std::endl;

#include <fstream>
using std::eek:fstream;

#include <cstdlib>
#include <string>
using std::string;

#include &quot;Log.h&quot;

#define fName &quot;try.log&quot;

Log::Log(){ openFile (); }
Log::~Log(){
if (outFile.is_open())
closeFile();
}

void Log::appendLog ( string logMsg ){
outFile << logMsg << &quot;\r\n&quot;;
}

void Log::appendLog ( unsigned long logMsg ){
outFile << logMsg << &quot;\r\n&quot;;
}

string Log::readLog (){
string str;

return str;
}

void Log::eek:penFile (){
outFile.open ( fName, ios::app );

if (!outFile){
cerr << &quot;File Could Not Be Opened&quot; << endl;
exit(1);
}
}

void Log::closeFile (){
outFile.close();
}
----------------------------------------------

i was facing problem on compilation when i include this header file to other class... i have tried forward declaration but it bring worst.

Thanks,

zonique
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top