Multiple files, multiple headaches.

Ok Let's try to explain this.

I am trying to teach myself c++, as I simply can't afford to take a class. I understand that hard coding the data is not the best method, but I haven't learned to read / write files yet. I wanted to break this file apart, because I thought it would be easier to manage, and when I get to read/write files it would be simpler to copy/paste/find/replace than start from scratch.

So I eagerly made the data.h and data.cpp files with code blocks, and I added it to my project. I put all the #includes and prototypes in the data.h file. In the data.cpp, and main.cpp files I included the iostream,stdlib and <data.h>. I copied my structures.

I tried everything I can think of and I get:

"No such file/directory" - data.h", I tried changing the <>'s to quotes but it still insisted "data.h" could not be found.

So I copied the data.h file into the same directory as my cpp files. I guess it found it.

It told me I had set my functions to void... Duh, I knew that, I set them.

I switched a few more things around, and I get 'string' does not name a type.
It told me I was redefining all my structs. Another attempt says No member named whatever in stuct. I tried switching more things around, and got the same error messages. I deleted everything, and restored my backup and I am back to where I was before I started...

I have in a separate text file another 200 rooms already set up, a simple copy and paste will add them to my code, I left them out cause it was simply way to damn long.

My code is here in one file and working:

My attempts to break up the file and not working:

What am I doing wrong?

In your header file, you're not using namespace std. THAT'S GOOD. Instead of using namespace std in your headers, you're going to need to prefix everything from the standard standard library with std::. Example:
struct word
    std::string word;
    int code;

This is actually a good habit for source files too.

First, Thank you for your reply Albatross. Once you got me past that little hurdle, the errors came out in abundance as I assume you knew they would.
I spent all day checking semi colons and braces. I rewrote a few functions and added a few returns, which got rid of all my warnings. I learned about extern, and put a few new tools in my arsenal. Thank you for putting me on the right track.

My most recent version is @

I have it down to 4 errors that I am having trouble with.

set__rooms, set_directions, set_verbs, and set_nouns was not declared in this scope.

The calls to these functions are in main.cpp and the functions are in data.cpp.

Can someone again put me on track please?
Topic archived. No new replies allowed.