Createing a Text File utility structure

I'm working on creating a text file writing structure so I don't have giant chunks of code cluttering up main. For reasons beyond my comprehension the compiler refuses to recognize the Image2D datatype I already created in another file that works perfectly fine with other classes and main. I've never had this problem before in writing classes but I'm very new to writing structures so I'm sure I must be doing something simple wrong. Any help would be greatly appreciated.

Save .h:
1
2
3
4
5
6
7
#pragma once

struct Save
{
	bool TextSave(const char * const fname, Image2D Img1);
};


Save .cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "StdAfx.h"
#include "Save.h"
#include "Image2D.h"

bool Save::TextSave(const char * const fname, Image2D Img1)
{	
	ofstream fout(fname);
	if (fout.is_open())
	{
		// NB failbit, badbit, eofbit
		if (!fout.fail() && !fout.bad() && !fout.eof())
		{
			fout << "1\n";
			fout << Img1.GetText() << '\t' << int(Img1.GetFG()) << '\t' << int(Img1.GetBG()) << '\n';
			
		}
		fout.close();
		cout << "save successful";
		return true;
	}
	else
		cout << "Couldn't open the file!";
	return false;
}

Save.h needs to #include "Image2D.h" because you are trying to use a Image2D object.
If it were a pointer or a reference, a forward declare would be enough.
this is more of a compiler question but why was it giving me crap about it in the cpp file and pretended like the .h file was perfectly fine?

I don't understand compiler error messages AT ALL and this kind of little stuff is killing me in programming classes. I desperately need to learn what exactly error messages mean so I don't have to stop working on something until I find someone to help me find what's wrong. Where can I get this kind of information? Without it there is no way in hell I'm going to survive my degree program long enough to get to the class that actually explains this so I can diagnose my own stupid little errors.
Posting the compiler message would help.
g++ -c  -Wall -O2 Save.cpp
In file included from Save.cpp:2:0:
Save.h:6:42: error: ‘Image2D’ has not been declared
Save.cpp:9:6: error: prototype for ‘bool Save::TextSave(const char*, Image2D)’ does not match any in class ‘Save’
Save.h:6:7: error: candidate is: bool Save::TextSave(const char*, int)
It points to Save.h.
The other error is crap, but it was derived from the first (I suppose that it assumes int if it does not know the type)

When you include a header, its contents gets copy-paste at the inclusion point. You can check that by stopping at the preprocessor output.
For gcc it would be the '-E' flag.

The compiler gets the preprocessor output, so I guess that it does not know to wich file it belongs.
Still, you could issue it to a wish list.


I desperately need to learn what exactly error messages mean (...) Where can I get this kind of information?
RTFM.
Or ask (provide message and code example)
RTFM... as in the c++ primer? Microsoft Visual Studio Help? WFM?!

-thanks
Topic archived. No new replies allowed.