User defined variables in multiple classes?
I have a struct:
typedef struct
{
CString m_csFileName;
CString m_csFilePath;
int Type, NumLayers,NumDir,NumPose;
}FILE_INFO;
and I want one class to have a number of variables of this type and I want other classes to be able to return this struct.
The problem with this is that if i declare FILE_INFO* CharFiles in my one class I need to have the struct defined before that class is defined. This is fine I put the struct at the top of class.h and everything is fine. But when in class2.h I have:
FILE_INFO* GetChars(blah)
This file knows nothing of FILE_INFO if I put #include "class.h" in the class2.cpp file. I can #include any header files in a different header file because then i get a load of multiple defined stuff.
If you can understand what i am asking (and I realise I havent explained it very well) how can i use this struct in different classes?
Thanks very much for your time and any help you can offer.
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
What you have to do is when you add the "include.h" file into the second file you have to put a
Then you also have to edit the orginal .h file to have this a the top before any code.
#ifndefine CODE_H
#define CODE_H
rest of the file.....
#endif
This will allow the structs to be created once. I hope this helps you.
Also you could use pointers to the struct. And the pass the structure to the functions and then edit the structure and return it pointer. That is just another suggestion.
Minerjr
Edited by - minerjr on June 18, 2001 6:54:41 AM
#define "C"{#include "include.h"}
Then you also have to edit the orginal .h file to have this a the top before any code.
#ifndefine CODE_H
#define CODE_H
rest of the file.....
#endif
This will allow the structs to be created once. I hope this helps you.
Also you could use pointers to the struct. And the pass the structure to the functions and then edit the structure and return it pointer. That is just another suggestion.
Minerjr
Edited by - minerjr on June 18, 2001 6:54:41 AM
Yes! It worked, sort of. It didnt like:
#define "C"
{
#include "include.h"
}
but it worked when i tried it with just #include "include.h"
Thanks very much
#define "C"
{
#include "include.h"
}
but it worked when i tried it with just #include "include.h"
Thanks very much
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
It should be:
Edited by - Dactylos on June 18, 2001 7:21:26 AM
|
Edited by - Dactylos on June 18, 2001 7:21:26 AM
minerjr>yeah thanks a lot you did help
but why do I need the extern if it works without the extern?
but why do I need the extern if it works without the extern?
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
No reason for using extern "C" here. That is for when you are declaring functions/data that has C linkage, eg the code is in an object file produced by a C compiler. That is not the case here, so just forget the extern all together and just put inclusion guards around the header.
Furthermore, if your only works with pointers to FILEOBJ, you don''t even need to include that header:
You don''t need to include filobj.h in this header file. If your class uses FILOBJ in any other way, however, like needing to construct one or refer to its members, you''ll have to include the fileobj header with the definition.
|
You don''t need to include filobj.h in this header file. If your class uses FILOBJ in any other way, however, like needing to construct one or refer to its members, you''ll have to include the fileobj header with the definition.
Thanks guys.
Stoffel> Ill have to include the header because the class needs to refer the the structs memberr
Thanks again guys
Stoffel> Ill have to include the header because the class needs to refer the the structs memberr
Thanks again guys
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement