LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-03-2004, 01:01 PM   #1
arnab_be
LQ Newbie
 
Registered: Mar 2004
Posts: 3

Rep: Reputation: 0
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
 
Old 03-03-2004, 01:47 PM   #2
lsmith
Member
 
Registered: Feb 2004
Posts: 40

Rep: Reputation: 15
Post the errors you are getting and I can try and work them out with you.
 
Old 03-03-2004, 02:23 PM   #3
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problems with compiling kopete (/lib/cpp error) mac1234mac Programming 1 09-14-2005 01:26 PM
gcc header files and cpp files? EchO Linux - Software 3 03-01-2005 01:14 AM
/lip/cpp error when compiling mep]-[isto Linux - Newbie 1 12-22-2003 06:44 AM
Problems when trying to compile cpp files using qt headers siphiuel Linux - Software 2 08-12-2003 04:41 AM
Problems when trying to compile cpp files using qt headers siphiuel Linux - Software 2 08-10-2003 07:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration