• Advertisement
Sign in to follow this  

typedefs, classes and scope

This topic is 2331 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

I have a header file for a particular class that contains the class definition as well as a couple typedefs like below:


typedef std::map<std::string, sf::Image> ImageMap;
typedef std::map<std::string, sf::somethingelse> DifferentMap;

typedef struct ResourceHeader
{
char n1;
char n2;
char n3;
};

class TestClass
{
private:
//blah

public:
//blah
};


The 3 typedefs in the above example are used only by the functions in that class, so would be it proper to declare the whole thing like this:


class TestClass
{
private:
typedef std::map<std::string, sf::Image> ImageMap;
typedef std::map<std::string, sf::somethingelse> DifferentMap;

typedef struct ResourceHeader
{
char n1;
char n2;
char n3;
};

//blah

public:
//blah
};


And that is my question, thanks.

Share this post


Link to post
Share on other sites
Advertisement
Nested sounds good. Wrapping it all up in a namespace may be good as well. Just a note, in C++, you don't need to put "typedef" in front of your structs.

Share this post


Link to post
Share on other sites
Thanks for the responses. I thought nesting would be the way to go, but I didn't know if it was excessive or not. Also, thanks Cornstalks for letting me know about the unnecessary typedef on the struct; I didn't know that.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement