Jump to content
  • Advertisement
Sign in to follow this  
jamesleighe

Silly Style Question

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

Sub-Classes:
A

class Mesh
{
public:
class LockData
{
;
};

LockData* Lock( );
};

or B

class MeshLockData
{
;
};

class Mesh
{
public:
MeshLockData* Lock( );
};

My main issues with A is that it makes my headers ugly; having classes with allot of sub-classes can be very hard to read.
It also forces me to include the header into my pure virtual interface headers since I can't use forward declarations for the sub-classes. (As far as I know!)

The main problem with B that I can think of is that it will expose internal-use-only 'private' classes to the world! (surely a horrible thing :P)

What would you do?

Share this post


Link to post
Share on other sites
Advertisement

You can forward declare your nested classes. Why do you think you can't?


Never seem to be able to using something like this:

class Class::SubClass;

Share this post


Link to post
Share on other sites
You can put implementation information in a detail namespace to avoid polluting the main namespace:

namespace Detail {
struct Foo {};
}

struct Bar {
Detail::Foo * moo();
};

and you can forward declare nested classes:

struct Baz {
struct Inner;
Inner * moo();
};

struct Baz::Inner {
};

Share this post


Link to post
Share on other sites


struct Baz {
struct Inner;
Inner * moo();
};

struct Baz::Inner {
};


To be clear, the [font="Courier New"]Baz[/font] definition goes in the header file, the [font="Courier New"]Baz::Inner[/font] definition goes in the .cpp file.

Share this post


Link to post
Share on other sites

To be clear, the [font="Courier New"]Baz[/font] definition goes in the header file, the [font="Courier New"]Baz::Inner[/font] definition goes in the .cpp file.


Is it required to? Wouldn't this work?
//All in the header
struct Baz {
struct Inner;
Inner * moo();
};

//Still in the same header.
struct Baz::Inner
{
//definition.
};

Share this post


Link to post
Share on other sites
It's not required. It can go in a source file if the behavior is supposed to be completely opaque to all callers. It can go into the same header as the enclosing class if it's part of the class' interface. It can also go into a second header that might be in a detail/implementation subdirectory.

Share this post


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

  • 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!