小编Ric*_*h L的帖子

为什么C++ 11引入了委托构造函数?

我无法理解委托构造函数的用途.简单地说,没有委派构造函数就无法实现的目标?

它可以做这样简单的事情

class M 
{
 int x, y;
 char *p;
public:
 M(int v) : x(v), y(0), p(new char [MAX]) {}
 M(): M(0) {cout<<"delegating ctor"<<endl;}
};
Run Code Online (Sandbox Code Playgroud)

但我不认为值得为这么简单的事情引入新功能吗?可能是我无法认识到重要的一点.任何的想法?

c++ c++11

23
推荐指数
3
解决办法
1万
查看次数

内联方式禁用铿锵的检查

我正试图为一个项目设置铿锵声.我希望能够提供干净的输出,并鼓励尽可能使用-fix模式.但是,在某些情况下需要例外.

很有可能使用

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreserved-id-macro"
// Code that is being specially exempted
#pragma clang diagnostic pop
Run Code Online (Sandbox Code Playgroud)

对于想要在本地禁用编译器警告的等效情况,是否可以通过clang-tidy执行类似的操作?

我试过了

#pragma clang diagnostic push
#pragma clang diagnostic ignored "readability-identifier-naming"
// Code that is being specially exempted
#pragma clang diagnostic pop
Run Code Online (Sandbox Code Playgroud)

并且还clang替换为clang-tidy.不幸的是,当clang用作pragma目标并使用常规clang进行编译时,我得到了编译警告

warning: pragma diagnostic expected option name (e.g. "-Wundef") [-Wunknown-pragmas]
Run Code Online (Sandbox Code Playgroud)

warning: unknown pragma ignored [clang-diagnostic-unknown-pragmas]
Run Code Online (Sandbox Code Playgroud)

编译时,如果我用来clang-tidy代替clang.clang-tidy在源上运行时,都不会对自身的输出产生影响.

这与x86_64 Linux上的3.8 clangclang-tidy.

c++ clang++ clang-tidy

17
推荐指数
2
解决办法
7557
查看次数

从FileInfo打开文件

在golang中,如果我有一个os.FileInfo,有没有办法在*os.File没有原始路径的情况下自己打开它?

假设我有这样的事情:

package main

import (
    "os"
    "path/filepath"
    "strings"
)

var files []os.FileInfo

func walker(path string, info os.FileInfo, err error) error {
    if strings.HasSuffix(info.Name(), ".txt") {
        files = append(files, info)
    }
    return nil
}

func main() {
    err := filepath.Walk("/tmp/foo", walker)
    if err != nil {
        println("Error", err)
    } else {
        for _, f := range files {
            println(f.Name())
            // This is where we'd like to open the file
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法转换FileInfo* …

go

15
推荐指数
2
解决办法
1万
查看次数

为cython包装枚举类

我试图将一个枚举类包装在c ++头文件中,以便在cython项目中使用.我已经google了一下,无法找到如何实现这一点 - 是否支持?

c++ cython c++11 enum-class

10
推荐指数
3
解决办法
2818
查看次数

标签 统计

c++ ×3

c++11 ×2

clang++ ×1

clang-tidy ×1

cython ×1

enum-class ×1

go ×1