I can't seem to figure out why but I get a compile time error with some of my files if I don't put a ; before using namespace std eg)
;using namespace std;
If I place the semicolon at the end of the line above or omit it altogether I will get an error. This is only with some files though and I can't seem to figoure out why. Below are two of my header files, one which needs the semi-colon and the other doesn't. If someone could point out why this is necessary it would be greatly appreciated.
Here is one that requires it:
Code:
//--------------------------------------------------------------------------------------------------
// Include Directive
//--------------------------------------------------------------------------------------------------
#ifndef AUTOMOBILE_H
#define AUTOMOBILE_H
#include <string>
;using namespace std;
//--------------------------------------------------------------------------------------------------
// A class that holds information about an automobilie including the Id, Make, Model, Mileage
// and cost. Contains methods to get and set each of these parameters as well as a toString()
// method that will return these parameters in a readable string
//--------------------------------------------------------------------------------------------------
class Automobile
{
public:
// Returns a string with column headings that match up with the string returned from
// toString()
string formatHeader();
// Returns the cost of the car
float getCost();
// Returns the Id of the car
string getId();
// Returns the make of the car
string getMake();
// Returns the mileage of the car
int getMileage();
// Returns the model of the car
string getModel();
// Sets the car's unique Id number
void setId(string argId);
// Sets the make of the car
void setMake(string argMake);
// Sets the model of the car
void setModel(string argModel);
// Sets the mileage of the car
void setMileage(int argMileage);
// Sets the cost of the car
void setCost(float argCost);
// Converts the car's parameters into a readable string
string toString();
private:
// The unique identification number for the car
string mId;
// The make of the car
string mMake;
// The model of the car
string mModel;
// The mileage of the car
int mMileage;
// The cost of the car
float mCost;
}
#endif
This one doesn't require it:
Code:
//--------------------------------------------------------------------------------------------------
// Include Directive
//--------------------------------------------------------------------------------------------------
#ifndef TOKENIZER_H
#define TOKENIZER_H
#include <string>
using namespace std;
//--------------------------------------------------------------------------------------------------
// A class that will take strings and tokenize them
//--------------------------------------------------------------------------------------------------
class Tokenizer
{
public:
// Tokenizes the passed string into an array of strings using the passed character as the
// delimiter between tokens
int tokenize(string str, string tokens[], char delim);
}
#endif
I picked two header files whose include directives are as similar as possible because this is what has baffled me the most. The include directives are nearly identical in these files as you can see.