struct in class
If I remeber correctly there was a way to declare and use a struct in a class, where you fill the struct in another part of the program:
// some.h
class sample{
public:
struct HERE;
};
// main.cpp
#include some.h
...
struct HERE{
int x;
};
...
This was possible right? Can anyone give me an example please?
Try this:
Hope that helps.
John.
//some.hstruct Struct { int member1; int member2;};class Class { private: int member1; int member2; public: Struct classStruct; //rest of class};
//some.cppint main() { int variable; Class myclass //...later in the function myclass.classStruct.member1 = variable; //...rest of function}
Hope that helps.
John.
You can do it if the member is a pointer or a reference:
class AClass
{
struct AStruct* s;
};
// somewhere else
struct AStruct
{
};
Of course any code which actually uses s needs to have the declaration of AStruct included.
[edited by - JuNC on August 27, 2002 4:46:53 PM]
class AClass
{
struct AStruct* s;
};
// somewhere else
struct AStruct
{
};
Of course any code which actually uses s needs to have the declaration of AStruct included.
[edited by - JuNC on August 27, 2002 4:46:53 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement