Jump to content
  • Advertisement

Archived

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

Pipo DeClown

struct in class

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Try this:


  

//some.h


struct Struct {

int member1;
int member2;

};

class Class {

private:

int member1;
int member2;

public:

Struct classStruct;

//rest of class

};



  
//some.cpp


int main() {

int variable;
Class myclass

//...later in the function


myclass.classStruct.member1 = variable;

//...rest of function


}


Hope that helps.

John.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!