samedi 4 janvier 2020

Instantiate std::atomic<> with a user-defined type UDT. If UDT has virtual function,l inkage will fail.Why?

here is an example:

#include <atomic>
using namespace std;

struct udt
{
    int a;
    virtual int get() 
    {
        return a;
    }
};

main()
{
    udt y;
    atomic<udt> x;
    x=y;
}

compiling the program with gcc fails at the linkage stage,the error message is undefined reference to `__atomic_store_16'. Removing the virtual keywork of udt::get() can fix this issue. I can't understand why udt cannot have virtual function when it is used to instantiate std::atomic<>

Aucun commentaire:

Enregistrer un commentaire