Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I indent do nothing initialization list constructors? [closed]

Example: Thread::Thread:

class Thread
{
    Process * parent_;
    unsigned __int32 id_;
    void * entryPoint_;
public:
    Thread(Process * parent, unsigned __int32 id, void * entryPoint) : 
        parent_(parent),
        id_(id),
        entryPoint_(entryPoint)
    {
    }
    unsigned __int32 GetId() const
    {
        return id_;
    }
    void * GetEntryPointAddress() const
    {
        return entryPoint_;
    }
};

I can't seem to come up with a way of indenting things so that it doesn't look strange... and yet this is a common pattern. What are common ways of indenting this?

like image 309
Billy ONeal Avatar asked Jan 09 '11 21:01

Billy ONeal


1 Answers

I always put empty blocks on a single line – i.e. { } (notice the space!).

Furthermore, I usually put the colon and commas in front of the initialization list members instead of after – this makes adding members later on easier.

Thread(Process * parent, unsigned __int32 id, void * entryPoint)
    : parent_(parent)
    , id_(id)
    , entryPoint_(entryPoint)
{ }

(Edit: I no longer follow this style myself: I omit the space between braces nowadays.)

like image 138
Konrad Rudolph Avatar answered Sep 21 '22 17:09

Konrad Rudolph