# C++ Class Declerations

This topic is 3892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Greetings, greetings, I'm using Code::Blocks to create a project, and I'm confused about the concept of class declerations, as C::Bs outputs, what seems to be, contradicting errors. Now, I have two classes. We'll call them Logger, and Window for simplicity.
// utility.h ---------
#include <mylogger.h>
#include <mywindow.h>

// main.cpp ----------
#include <utility.h>

// mylogger.h --------
#include <utility.h>

class Logger
{
...
};

// mywindow.h --------
#include <utility.h>

class Window
{
public:
myfunc( ..., Logger * );
}

Keep in mind, this is really trimmed down, and has header guard words etc., etc., but I think it gets my point across. Now at mywindow.h, in myfunc() C::Bs says that Logger has not been declared - however - changing mywindow.h to the following says that Logger is already declared, and I can't declare it again.
// mywindow.h ---------
#include <utility.h>

class Logger { };

class Window
{
public:
myfunc( ..., Logger * );
}

I'm curious what I'm doing wrong, how to set the Logger class as a parameter, and is there a better way to tell the Window class to use Logger? -- Aaron

##### Share on other sites
To do a forward declaration (what you're trying to do in the second part of your post), you don't need (or want) the {}'s. Just plain ol':

class Logger;

And don't forget to include mylogger.h in mywindow.cpp!

##### Share on other sites
Thanks, works like it should now, but I can't shake the feeling that I might be dumbing down my system by having to declare the class fowardly. I would think that since both files include the utility, which includes the Logger, then the Window - that Logger would already be declared and ready for use. Aparently thats not so though.

-- Aaron

##### Share on other sites
You may be including <mywindow.h> somewhere which caused your error. In visual studio ther is an option to tell the compiler to ouput explicitly the included files for each cpp. I don't know about Cb but if such an option exists it might help you.

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 32
• ### Forum Statistics

• Total Topics
632630
• Total Posts
3007522
• ### Who's Online (See full list)

There are no registered users currently online

×