Skip to main content
GameDev.net gamedev.net
🔒 Locked

Silly Style Question

Started by jamesleighe Dec 7, 2011 at 5:03 PM 5 replies 1.1k views
Original Post
jamesleighe
jamesleighe
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 )

What would you do?
Bregma
Bregma
You can forward declare your nested classes. Why do you think you can't?
Stephen M. Webb
Professional Free Software Developer
jamesleighe
jamesleighe

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;
SiCrane
SiCrane
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 {
};
Bregma
Bregma


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.
Stephen M. Webb
Professional Free Software Developer
Servant of the Lord
Servant of the Lord

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.
};
SiCrane
SiCrane
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.