我应该如何缩进不执行任何初始化列表构造函数?

发布于 2024-10-11 07:07:47 字数 1431 浏览 12 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

苏佲洛 2024-10-18 07:07:47

我总是将空块放在一行上 - 即 { } (注意空格!)。

此外,我通常将冒号和逗号放在初始化列表成员的前面,而不是后面 - 这使得以后添加成员变得更容易。

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

(编辑:我自己不再遵循这种风格:现在我省略了大括号之间的空格。)

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.)

一花一树开 2024-10-18 07:07:47

我就是这样做的:

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

但是你的方式对我来说并不奇怪。

This is how I do it:

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

But your way does not look strange to me.

潜移默化 2024-10-18 07:07:47

以下是我如何按照

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

Google 风格(至少是 protobuf)进行操作:

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

Here's how I do it

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

Google style (atleast protobuf), would be:

public:
 Thread(Process * parent, 
        unsigned __int32 id, 
        void * entryPoint) 
  : parent_(parent),
    id_(id),
    entryPoint_(entryPoint) { }
寄居者 2024-10-18 07:07:47

以下是我的做法,以及为什么我没有发现你的示例有任何问题:

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

就我而言,按照你的方式去做:只要你是自洽的并且与你正在从事的项目保持一致,您的缩进样式是什么并不重要

Here's how I do it, and why I don't see anything wrong with your sample:

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

As far as I'm concerned, do it your way: As long as you are self-consistent and consistent with the project you're working on, it doesn't matter what your indentation style is.

你是年少的欢喜 2024-10-18 07:07:47

我建议在空的构造函数主体中添加注释,这样任何阅读代码的人都知道您希望它为空。这样他们就可以确定这不是您忘记在那里插入代码的情况。

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

I'd recommend putting a comment into the empty constructor body, just so anyone reading the code knows that you intended it to be empty. That way they can be certain that it's not a case of you having forgotten to insert code there.

Thread(Process * parent, unsigned __int32 id, void * entryPoint) : 
    parent_(parent),
    id_(id),
    entryPoint_(entryPoint)
{
    // empty
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文