这是一个例子:#include <atomic>using namespace std;struct udt{ int a; virtual int get() { return a; }};main(){ udt y; atomic<udt> x; x=y;}在链接阶段使用gcc编译程序失败,错误消息是未定义对`__atomic_store_16'的引用。删除udt::get()的虚拟键盘可以解决此问题。我不明白为什么udt用于实例化std::atomic 时不具有虚函数 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 [atomics.types.generic]/1 The template argument for T shall be trivially copyable... [class]/6 A trivially copyable class is a class: (6.1) — where each copy constructor, move constructor, copy assignment operator, and move assignment operator (15.8, 16.5.3) is either deleted or trivial... [class.copy.ctor]/11 A copy/move constructor for class X is trivial if it is not user-provided and if: (11.1) — class X has no virtual functions (13.3) and no virtual base classes (13.1)...udt不可复制。通过将模板参数传递给标准库中的模板,您的程序表现出未定义的行为,这违反了该模板的要求。 (adsbygoogle = window.adsbygoogle || []).push({}); 10-08 11:56