C++ Classes within a namespace

Started by
15 comments, last by Kimeli 18 years, 7 months ago
You probably meant 3.4.2 - there is no 4.3.

I'm using 3.4.4 (with code::blocks, too).
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
Yep, I'm dyslexic. [wink] I just upgraded to 3.4.4 and it still doesn't compile. I checked the build options to make sure there wasn't anything unusual in there and it was all set to the defaults.

Here is the zip that contains the project file too. Won't build under a clean install of code::blocks. [wow] Any ideas?
I'm just creating an ordinary C++ console project and adding your files to it... and it compiles.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Doesn't compile with the Visual C++ 2003 toolkit under code::blocks either, unless I remove the .cpp files from the project.
Quote:Original post by tstrimp
Doesn't compile with the Visual C++ 2003 toolkit under code::blocks either, unless I remove the .cpp files from the project.


-Remove #include "lwg.h" from lwg_task.h (there is no reason why this should be here)
-Replace #include "lwg.h" from lwg_kernel with #include "lwg_task.h"

Notes!

- Use include guards (in headers) for example:

#ifndef _FOOBAR_H_
#include "foobar.h"
#endif

- Use forward declarations (when possible)

class Foobar;

- Dont include anything useless
Quote:Original post by Kimeli
-Remove #include "lwg.h" from lwg_task.h (there is no reason why this should be here)
-Replace #include "lwg.h" from lwg_kernel with #include "lwg_task.h"


There isn't a reason now. But there might be later. Is there not a way to have an all inclusive includes header for the projet?

Quote:
Notes!

- Use include guards (in headers) for example:

#ifndef _FOOBAR_H_
#include "foobar.h"
#endif


If you look at the source download then you would notice I am using them. Also
Quote:Original post by tstrimp
Each of my header files have guard blocks on them to prevent them from being included more then once


Quote:
- Use forward declarations (when possible)

class Foobar;

- Dont include anything useless


This has nothing to do with it. The only problem is within the namespace. If I take them out of the namespace there isn't any problems.
Your problematic file is lwg_task.cpp.
Just follow the includes and You will see why it dont compile.

lwg_task.cpp:
#include "lwg_task.h"

lwg_task.h:
#ifndef _LWG_TASK_H
#define _LWG_TASK_H

#include "lwg.h"

lwg.h:

#include "lwg_task.h"

lwg_task.h:
#ifndef _LWG_TASK_H <<< already defined so it skips Task class declaration etc.

lwg.h:

#include "lwg_kernel.h"

lwg_kernel.h:
[clip]
private:
lwg::Task t; <<< this one is not yet declared
[/clap]

This has nothing to do with namespaces. :)

This topic is closed to new replies.

Advertisement