user2374728
user2374728

Reputation: 1

Custom header file not being included

working on a college assignment, we're required to write around a provided main.cpp file, giving a translator.h and translator.cpp file. This code compiles and works if I combine it all together into a single .cpp file, but as separate files, it looks as if the header file isn't being recognized, and the compiler throws a load of

I tried using namespace std in the header file, I realize I shouldn't use namespace std as it's bad practice, but it didn't make a difference anyway.

Much appreciated. These are the errors (continuing in this fashion all the way down)

Translator.cpp:1:1: error: 'Translator' does not name a type
Translator::Translator(const char dictFileName[]) : dictionary(dictFileName)
^
Translator.cpp:5:6: error: 'Translator' has not been declared
void Translator::toElvish(char * outputline, const std::string inputline)
  ^
Translator.cpp:5:52: error: 'string' in namespace 'std' does not name a type
void Translator::toElvish(char * outputline, const std::string inputline)
                                                ^

The code is linked http://pastebin.com/Nwh7mh6D (I think it's probably a bit long for the body of a post like this.

Thanks again.

Upvotes: 0

Views: 1185

Answers (1)

Joseph Mansfield
Joseph Mansfield

Reputation: 110748

The problem is that your translator.cpp doesn't #include "translator.h". It also needs to be able to see the class definition and member function declarations. The compiler doesn't care that the two files both happened to be named in the same way and so doesn't automatically connect them together.

Upvotes: 2

Related Questions