Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Compilation err...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 43339 of 47561
Post > Topic >>

Compilation error with seperate compilation

by C__chp <nheiligers@[EMAIL PROTECTED] > Feb 15, 2008 at 03:30 AM

Can anyone help me with the following problem
When i compile a program which is devided in three files and i compile
with GCC i'm getting the follwong error
However when i put it in one file it conpiles and runs perfectly
So it has probaly something to do with the includes , but i do not see
what
Many regards
Nico Heiligers

**** Build of configuration Debug for project acc ****
**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -oreadadfile.o ..
\readadfile.cpp
In file included from ..\readadfile.cpp:1:
...\adfile.h:12: error: ISO C++ forbids declaration of `vector' with no
type
...\adfile.h:12: error: expected `;' before '<' token
...\adfile.h:14: error: `string' does not name a type
...\readadfile.cpp:5: error: expected initializer before "Adfile"
...\readadfile.cpp:6: error: expected constructor, destructor, or type
conversion before '.' token
...\readadfile.cpp:7: error: expected constructor, destructor, or type
conversion before '.' token
...\readadfile.cpp:8: error: expected declaration before '}' token
Build error occurred, build is stopped
Time consumed: 172 ms.

these are the files
h file for class decalration adfile.h
#ifndef ADFILE_H_
#define ADFILE_H_

class Adfile
{
public:
Adfile(char*);
~Adfile();
void readFile(void);
void displayFile(void) const;
private:
vector<string> v;
char* filename;
string line;
};
#endif /*ADFILE_H_*/

the compiler is marking an error at lines

 vector<string> v;
and
string line

===============================

implementation cpp file: adfile.cpp
#include "adfile.h"
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;


Adfile::Adfile(char* str)
{
filename = str;
}
Adfile::~Adfile()
{
}

void Adfile::readFile(void)
{
ifstream in(filename);
while(getline(in, line))
v.push_back(line);
}

void Adfile::displayFile(void) const
{
for(unsigned int i = 0; i < v.size(); i++)
cout << i << ": " << v[i] << endl;
}

main program file:
#include "adfile.h"

int main(void)
{
Adfile adfile("Fillvector.cpp");
adfile.readFile();
adfile.displayFile();
} ///:~

==========================================
 




 5 Posts in Topic:
Compilation error with seperate compilation
C__chp <nheiligers@[EM  2008-02-15 03:30:04 
Re: Compilation error with seperate compilation
Keith Halligan <keith.  2008-02-15 03:57:34 
Re: Compilation error with seperate compilation
Ko van der Sloot <Ko.v  2008-02-15 14:07:30 
Re: Compilation error with seperate compilation
Richard Herring <junk@  2008-02-15 13:45:27 
Re: Compilation error with seperate compilation
Puppet_Sock <puppet_so  2008-02-15 07:57:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 3:33:51 CDT 2008.