Sign in to follow this  
SirLuthor

Random error occurences? [ NOT Solved]

Recommended Posts

I'd really love to wait until my earlier thread is off the top of the list, as spam is something everyone is willing to give, but no one wants, but regrettably, time is not a resource I currently have masses of, so I'll have to post this now. I'm having a big problem. I have a project (not even near completion) which compiles fine. Now, in that project, I have a class called 'Task', in the 'ASC-Task.hpp' file, as seen here: ASC-Task.hpp
#ifndef ASC_TASK_HPP
#define ASC_TASK_HPP

#include "ASC-Define.hpp"
#include "ASC-TaskManager.hpp"
#include "ASC-Callbacks.hpp"

namespace ASC
{
	namespace Core
	{
		class Task
		{
			public:
				Task();
				virtual ~Task();

				virtual ASCCB * Update() = 0;
				virtual ASCCB * OnKill() = 0;

				friend class TaskManager;
			protected:
				void SetVals(ASCSINT id, ASCSTRING name, ASCSTRING desc);

				ASCSINT	taskID;
				ASCSTRING taskName;
				ASCSTRING taskDescription;
			private:
		};
	}
}

#endif




Now, that looks fine, is implemented (not the pure virtual functions of course..) and compiles just fine with the rest of my project. However, when I add another header file, 'ASC-EntryTask', which inherits from ASC::Core::Task, I get a host of odd syntax errors in every single file, where there were none before. And I don't mean a small amount of errors, where there were 0, now there are 646... And that seems VERY odd to me, because nothing has changed in any of the files, except adding the '#include ".\Core\ASC-EntryTask.hpp" to the shared header file that all .cpp files include. Here's an example of one of the vexing errors.. Get a load of this: error C2039: 'cout' : is not a member of 'std'. Not only that kind of error, but it's spitting out a load of syntax errors for no reason at all... Rather puzzling, to say the least. Anyway, without further ado, I give you 'ASC-EntryTask.hpp', the file which apparently is causing all my problems. ASC-EntryTask.hpp
#ifndef ASC_ENTRYTASK_HPP
#define ASC_ENTRYTASK_HPP

#include "ASC-Define.hpp"
#include "ASC-Task.hpp"

namespace ASC
{
	namespace Core
	{
		class EntryTask : public Task
		{
			public:
				EntryTask();
				~EntryTask();

				virtual ASCCB * Update() = 0;
				virtual ASCCB * OnKill() = 0;
			protected:
			private:
		};
	}
}

#endif




I really can't make anything of this, so if anyone here would be kind enough to perhaps tell me why everything is so screwed with the addition of that file, I'd be quite thankful [smile] Cheers! [EDIT] In case anyone notices the line: class EntryTask : public Task Should I include the full name there, that is, ASC::Core::Task there? Because it seems that at least for friend declarations, I can't do that, or it gives me an error. [Edited by - SirLuthor on February 9, 2005 5:10:45 AM]

Share this post


Link to post
Share on other sites
I use no 'using' directives at all.

In case it helps, I'm getting errors before every opening and closing brace, like:
error C2143: syntax error : missing ; before {
or
error C2143: syntax error : missing ; before }

Share this post


Link to post
Share on other sites
Sorry, I meant that you need this:

#include <iostream>
using namespace std;


Brain lapse where cout was located at [lol].


[edit]Hmm, check all of the .hpp files and make sure the classes have a ; at the closing brace.

[edit]
Here is a quick reference to namespaces. I'm thinking there may be a collision with the namespace usage somehow when you add that file in. What does the define.hpp look like as well as the other one.

Share this post


Link to post
Share on other sites
if your not putting it in as <iostream.h> you have to do "using namespace std".. just add a .h and it *should* work. At least, it does that on my compiler :).

~zix~

Share this post


Link to post
Share on other sites
If you are using Microsoft Visual C++, (may not be the only one with this problem, but the only one I've tested it on is this one.) all standard includes (incorrect usage of term? I meant iostream and all that) HAVE to come above all of your own includes.

I've found that if you don't put standard includes first, then you will get the errors you've listed.

Share this post


Link to post
Share on other sites
Quote:
Original post by zix99
if your not putting it in as <iostream.h> you have to do "using namespace std".. just add a .h and it *should* work. At least, it does that on my compiler :).

~zix~


No if about it, never use <iostream.h>. And you don't have to do "using namespace std", you can just pull out the bits you're actually using or use fully qualified names. Really, they stuck everything in that neat little container to avoid conflicts, dumping everything out into the global namespace kind of defeats the whole point.

Share this post


Link to post
Share on other sites
Drew_Benton: Regarding checking classes for missing ; Presumably, if I had a missing semi-colon somewhere, it would have been picked up by the compiler earlier, even before I added the ASC-EntryTask.hpp file in? As for ASC-define.hpp, it's just a load of #define's, like, '#define ASCCB ASC::Core::Callback', etc.

Lenox: I'll have a look and check if all my includes are ordered properly, I tend to put C++ standard includeds on top, in alphabetical order, followed by other includes, also in alphabetical order. But I'll check, hell, if that's the reason for all my errors, I'd be quite happy :)

Share this post


Link to post
Share on other sites
Oh. my. god. I hate it when I do that... Such a simple mistake, I probably never would have found it, if not by pure chance of having encountered something sort of like this a while back, which I had forgotten about.

Apparently, the problem was this: In the shared header, Ascendancy.hpp, the ASC-EntryTask.hpp was included above the ASC-Task.hpp file, which would lead to the 'EntryTask' class inheriting from a class not even declared when EntryTask was declared..

Of course, simple beginner's mistake as it was, that was a very vexing experience.. And I still can't figure out why it borked all my curly braces [smile].... Cheers folks, and thanks for the input! Apparently, #include'ing in alphabetical order is not always the optimal setup :D

Share this post


Link to post
Share on other sites
Quote:
Original post by SirLuthor
Oh. my. god. I hate it when I do that... Such a simple mistake, I probably never would have found it, if not by pure chance of having encountered something sort of like this a while back, which I had forgotten about.

Apparently, the problem was this: In the shared header, Ascendancy.hpp, the ASC-EntryTask.hpp was included above the ASC-Task.hpp file, which would lead to the 'EntryTask' class inheriting from a class not even declared when EntryTask was declared..

Of course, simple beginner's mistake as it was, that was a very vexing experience.. And I still can't figure out why it borked all my curly braces [smile].... Cheers folks, and thanks for the input! Apparently, #include'ing in alphabetical order is not always the optimal setup :D


:)

To avoid this problem, you should #include "ASC-Task.hpp" in ASC-EntryTask.hpp. This costs nothing - well, maybe some compiler time, but I bet a difference of 20 milliseconds per file will not hurt you - and avoid this kind of errors.

One rule I always follow: if class B inherits from class A, then the declaration file of B includes the declaration file of A.

Regards,

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
Quote:
Original post by SirLuthor
Oh. my. god. I hate it when I do that... Such a simple mistake, I probably never would have found it, if not by pure chance of having encountered something sort of like this a while back, which I had forgotten about.

Apparently, the problem was this: In the shared header, Ascendancy.hpp, the ASC-EntryTask.hpp was included above the ASC-Task.hpp file, which would lead to the 'EntryTask' class inheriting from a class not even declared when EntryTask was declared..

Of course, simple beginner's mistake as it was, that was a very vexing experience.. And I still can't figure out why it borked all my curly braces [smile].... Cheers folks, and thanks for the input! Apparently, #include'ing in alphabetical order is not always the optimal setup :D


:)

To avoid this problem, you should #include "ASC-Task.hpp" in ASC-EntryTask.hpp. This costs nothing - well, maybe some compiler time, but I bet a difference of 20 milliseconds per file will not hurt you - and avoid this kind of errors.

One rule I always follow: if class B inherits from class A, then the declaration file of B includes the declaration file of A.


Seconded. One of the main reason for using those include guards in the first place is to allow you to do this.

Share this post


Link to post
Share on other sites
Actually, on second look, it doesn't seem to be the cause of my problem, this is recurrant.. I change some things in other files, and boom, nothing works anymore.. If someone could take a look at the source, And perhaps point out exactly what is causing this glut of errors, I'd be most obliged [smile] The VC 6 wokrspace and project files are also included, don't know why, but I figured I may as well throw them in..

Cheers!

BTW, Guys, I think you misunderstood my system. Perhaps if you took a look at the files, you would understand how my method works, as I clearly can not explain it well enough.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this