0

I'm having a problem with method declaration. I'm really new to C++ so I was hoping somebody could help. I'm including my header and part of. my source file

#ifndef HEADER_H
#define HEADER_H

#include <fstream>

using namespace std;

class employee
{
public:
void readData(ifstream & inf);

void Compute (int bp);

void print (ofstream & outf) const;

employee();

private:

int ID;
int Job_class;
int Years;
int Ed;
float sal;
};

#endif

Now the source file, I'm getting the error at void employee :: readData(ifstream&inf) Member Declaration not found. What am I missing here

#include <iostream>
#include <fstream>
#include <iomanip>
#include "employee.h"

using namespace std;

void employee ::readData(ifstream& inf)

{
inf >> ID >> Job_class >> Years >> Ed;
  • 1
    Please especially don't put `using namespace std;` in a header. In any case, [I don't get your error.](http://coliru.stacked-crooked.com/a/9cbd90dc3839b40e) – chris Mar 12 '14 at 01:08
  • What's the reasoning for not using that in the header? – user3404737 Mar 12 '14 at 01:13
  • 1
    @user3404737 because your header will be included by many other cpp files that want to use your code and in this case those cpp files all have to live with your `using namespace std` even if they don't want, you pollute the namespace of many cpp files. You should use `using namespace X` in a header only inside an inline function/method. In all other cases use it only in cpp files. – pasztorpisti Mar 12 '14 at 01:16
  • It's [bad in general](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-a-bad-practice-in-c), but putting it in a header forces everyone who includes that to suffer the losses. – chris Mar 12 '14 at 01:16
  • 1
    How are you compiling the code? Are you using command line or an actual IDE like Visual Studio? If command line please provide your compile instructions. – Matthew Pigram Mar 12 '14 at 01:20
  • 1
    You should definitely NOT use "using namespace" in headers because then by including that header in another program, the namespace will also get imported into that particular program, maybe without realizing, intending or wanting it (header inclusion can be very deeply nested). So put "using namespace" only in .cpp files... – soupso Mar 12 '14 at 01:26
  • What is your header called? Are you sure nothing else is defining `HEADER_H`? – vonbrand Mar 12 '14 at 01:55
  • Nothing else is defining it, and I'm also using Eclipse/Cygwin to compile/build. – user3404737 Mar 12 '14 at 02:07
  • The closing `}` is missing from the implementation of `readData` in your post. Assuming that is an oversight in your post and that you have the closing '}' in your code, there nothing in your code to prevent it from successfully compiling. – R Sahu Mar 12 '14 at 04:35
  • Best way to solve issues related to headers/defines is to generate the preprocessed file for your .cpp (for GCC use -E option). This will create one large file and show you what is actually being compiled after the preprocessor is done. – Yasser Asmi Mar 12 '14 at 07:05

0 Answers0