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 |
Post the errors you are getting and I can try and work them out with you.
|
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.
http://www.linuxquestions.org/rules.php And trying to post 3 times in the wrong forum is clearly against the rules. Please do not do it again. |
All times are GMT -5. The time now is 11:33 PM. |