gpt4 book ai didi

c++ - volatile 和非 volatile 实例的重载类

转载 作者:太空狗 更新时间:2023-10-29 20:44:06 26 4
gpt4 key购买 nike

我正在编写一个需要同时支持 volatile 和非 volatile 实例的类( volatile 实例使用原子操作,非 volatile 实例使用常规操作),并且想知道我是否以正确的方式进行处理。到目前为止,这是类声明的片段:

class Yield {
public:
Yield();
Yield(Yield const &other);
Yield(Yield const volatile &other);

Yield &operator=(Yield const &other);
Yield &operator=(Yield const volatile &other);

Yield &operator+=(Yield const &other);
Yield &operator+=(Yield const volatile &other);
Yield volatile &operator+=(Yield const &other) volatile;
Yield volatile &operator+=(Yield const volatile &other) volatile;

// Other operators snipped...
};
  • 问题 1:使用 MSVC 编译时,出现以下警告:

    警告 C4521:“util::Yield”:指定了多个复制构造函数

    此警告是否预示着使用此类时会出现任何问题?还是可以安全地忽略它?

  • 问题 2:就目前而言,所有运算符都针对 volatile 和非 volatile other 参数进行了重载。我认为这是必要的,以避免对非 volatile 实例进行较慢的 volatile 访问?是否有替代方法允许每个方法仅编码两次( volatile lhs 和非 volatile lhs)而不是 4 次( volatile 和非 volatile lhs,每个都有 volatile 和非 volatile rhs)?

    <

我希望把这些问题放在一起没问题,否则请发表评论,我可以拆分它们。谢谢!

最佳答案

The class has multiple copy constructors of a single type. This warning is informational; the constructors are callable in your program.

来自 msdn 网站:Compiler Warning (level 3) C4521

关于c++ - volatile 和非 volatile 实例的重载类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13867480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com