首页 > 解决方案 > 生成唯一 ID C++

问题描述

我想为我的复杂结构生成一个唯一标识符“ident”,我该怎么做?

在我的标题中,复杂的结构是:

struct Complexe {
    float x;
    float y;
    static unsigned int ident;
};

void Init(Complexe&);

etc...

在 cpp 文件中,我需要为 ident 赋予一个唯一的 int

Init(Complexe&z){
    z.ident = 0;
    z.y = 0;
    z.x = 0;
};

标签: c++structidentifier

解决方案


考虑 UUID,特别是 GNU/Linux 上的 uuid_generate,或者(似乎)Windows 上的 UuidCreate。


推荐阅读