#### Archived

This topic is now archived and is closed to further replies.

# C++ -> Class -> newbie -> problem ^__^

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

## Recommended Posts

Hi =) I've built a class CmyClass:

#ifndef MyClass_H
#define MyClass_H

class MyClass
{
bool	m_bool;
.....
.....
DWORD   m_dword;
public:
MyClass();
~MyClass() { Destroy(); }
void Destroy();
...other function ....
};

#endif

Then in file MyCLass.cpp I've write all method and function...

#include "MyClass.h"

MyClass::MyClass()
{
......
}

void MyClass::Destroy()
{
......
}

Now... I want use a MyCLass object in another Class MyApplication In MyApplication.h I've write this:

class MyApplication
{
BOOL  m_bXXX;
INT   m_iYYY;
MyClass* m_pZZZZ
.....
.......
}

The problem is that if I try to compile, I get this error message: 'MyClass': missing storage-class or type specifiers Why? Why doesn't see my class?? PS: in MyApplication.cpp I've write #include "MyClass.h" Good bye. [edited by - BlueChip on February 1, 2003 2:36:57 PM]

##### Share on other sites
You do have myclass.cpp in your new project, right?

##### Share on other sites
MyApplication uses a pointer to MyClass so needs to know the name MyClass. There are a few ways to do this.

1) You can let it know by putting the header file for MyClass before the header for MyApplication. This can be a) in the cpp file or b) actually in the MyApplication.h file.

    //a)in MyApplication.cpp#include "MyClass.h"#include "MyApplication.h"//or//b)in MyApplication.h#include "MyClass.h"class MyApplication{bool m_bXXX;int m_iYYY;MyClass* m_pZZZZ;

2) put a forward declaration, This is just the name of the class which satisfies the compiler until later. eg in MyApplication.h
Later when you are actually using the pointer to MyClass somewhere in the .cpp file you need to let the compiler see the whole declaration, that's so it knows what functions can be called etc. So in MyApplication.cpp you need to include MyClass.h

        //in MyApplication.hMyClass;// this satisfies the compilerclass MyApplication{bool m_bXXX;int m_iYYY;MyClass* m_pZZZZ;//in MyApplication.cpp#include "MyClass.h"#include "MyApplication.h"

Out of the two methods the second is foolproof (no chance of circular dependencies) and decreases needless dependencies between seperate sections of code. It will reduce the need to recompile when a header is changed.

By the way, when posting code here you can format it using [ source ] [/ source ] tags (omitting the spaces)

[edited by - petewood on February 1, 2003 1:04:45 PM]

##### Share on other sites
YEP =)

Thanks very very much....
I don''t belive that order of header was important.

quote:
By the way, when posting code here you can format it using [ source ] [/ source ] tags (omitting the spaces)

Yes... I do it now...
perhaps this topic will be usefull to other people.

1. 1
2. 2
JoeJ
17
3. 3
4. 4
5. 5
frob
11

• 13
• 16
• 13
• 20
• 12
• ### Forum Statistics

• Total Topics
632178
• Total Posts
3004608

×