LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   compiling .h and .cpp files with g++ (https://www.linuxquestions.org/questions/linux-newbie-8/compiling-h-and-cpp-files-with-g-153074/)

arnab_be 03-03-2004 01:01 PM

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

lsmith 03-03-2004 01:47 PM

Post the errors you are getting and I can try and work them out with you.

XavierP 03-03-2004 02:23 PM

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.