Silly Style Question

Started by
5 comments, last by SiCrane 12 years, 4 months ago
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?
Advertisement
You can forward declare your nested classes. Why do you think you can't?

Stephen M. Webb
Professional Free Software Developer


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


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


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

This topic is closed to new replies.

Advertisement