小编Mr.*_*Mr.的帖子

C++静态成员初始化(模板内部有趣)

对于静态成员初始化,我使用嵌套的帮助器结构,它适用于非模板化的类.但是,如果封闭类由模板参数化,则如果未在主代码中访问辅助对象,则不会实例化嵌套初始化类.为了说明,一个简化的例子(在我的例子中,我需要初始化一个向量).

#include <string>
#include <iostream>

struct A
{
    struct InitHelper
    {
        InitHelper()
        {
            A::mA = "Hello, I'm A.";
        }
    };
    static std::string mA;
    static InitHelper mInit;

    static const std::string& getA(){ return mA; }
};
std::string A::mA;
A::InitHelper A::mInit;


template<class T>
struct B
{
    struct InitHelper
    {
        InitHelper()
        {
            B<T>::mB = "Hello, I'm B."; // [3]
        }
    };
    static std::string mB;
    static InitHelper mInit;

    static const std::string& getB() { return mB; }
    static InitHelper& getHelper(){ return mInit; }
};
template<class T> …
Run Code Online (Sandbox Code Playgroud)

c++ templates initialization static-members

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

如何检查为给定路径启用POSIX ACL

在阅读getfacl/ setfacl我的手册页后,我找不到一个明显/健壮/优雅的方法来检查是否为(ba)sh中的给定路径启用了acl.

有什么建议?

unix bash acl posix

10
推荐指数
1
解决办法
3383
查看次数

标签 统计

acl ×1

bash ×1

c++ ×1

initialization ×1

posix ×1

static-members ×1

templates ×1

unix ×1