compiling .h and .cpp files with g++
Hi,
my problem is i have 2 header files and 2 cpp files. What should i type in the command line using g++ so that all these files could be successfully compiled?
Translator.h(abstract class declaration) is used in TextTranslator.h as TextTranslator.h is a derived class. Also, TextTranslator.cpp uses TextTranslator.h. Finally the main() lies in test.cpp. I am facing errors if i give the command:
g++ -g test.cpp -o test.
Do advise on the best course of action even if it means redesigning inheritance pattern and code.
I have 5 files in all :
1. test.cpp
#include"TextTranslator.h"
#include<fstream>
int main()
{
ifstream examplefile("readme.txt");
TextTranslator tt(examplefile);
tt.translation(examplefile);
return(0);
}
2. TextTranslator.cpp
#include"TextTranslator.h"
#include<iostream>
#include<fstream>
#include<stdlib>
TextTranslator :: TextTranslator(){
}
TextTranslator :: TextTranslator(ifstream examplefile){
if (! examplefile.is_open())
{
cout << "Error opening file";
exit (1);
}
}
void TextTranslator :: translation(ifstream examplefile)
{
ofstream outfile("readme.xml");
outfile << "<Document>\n";
outfile << examplefile.rdbuf();
outfile << "\n</Document>";
outfile.close();
}
3. TextTranslator.h
#include"Translator.h"
#include<fstream>
class TextTranslator : public Translator
{
public:
TextTranslator();
TextTranslator(ifstream examplefile);
};
4. Translator.h
#include<fstream>
class Translator {
public :
void translation();
};
5. readme.txt - a text file that is to be read and processed
|