我有一个std::atomic
,其中包含指向成员函数的指针。一切都在g ++ 4.4.5中编译得很好,但我在链接时遇到了这个错误:
./pool.o: In function `pool::worker::worker(pool&, int, int)':
pool.cpp:(.text._ZN4pool6workerC1ERS_ii[pool::worker::worker(pool&, int, int)]+0x95): undefined reference to `std::atomic<void (pool::* const*)(unsigned int, unsigned int, pool::worker*)>::store(void (pool::* const*)(unsigned int, unsigned int, pool::worker*), std::memory_order) volatile'
./pool.o: In function `pool::worker::give_job(void (pool::* const&)(unsigned int, unsigned int, pool::worker*), unsigned int, unsigned int)':
pool.cpp:(.text._ZN4pool6worker8give_jobERKMS_FvjjPS0_Ejj[pool::worker::give_job(void (pool::* const&)(unsigned int, unsigned int, pool::worker*), unsigned int, unsigned int)]+0x142): undefined reference to `std::atomic<void (pool::* const*)(unsigned int, unsigned int, pool::worker*)>::store(void (pool::* const*)(unsigned int, unsigned int, pool::worker*), std::memory_order) volatile'
./pool.o: In function `pool::worker::soul()':
pool.cpp:(.text._ZN4pool6worker4soulEv[pool::worker::soul()]+0xf1): undefined reference to `std::atomic<void (pool::* const*)(unsigned int, unsigned int, pool::worker*)>::store(void (pool::* const*)(unsigned int, unsigned int, pool::worker*), std::memory_order) volatile'
我真的不知道为什么它试图链接到store()
的volatile重载,其中在源中指向成员函数的指针是const
,而不是volatile
(和它编译)。
相同的代码用g ++ 4.6.3编译
答案 0 :(得分:3)
简单:GCC 4.4没有对此的支持,或者它以您经历的方式被打破。较新的GCC有更好的支持,它的工作原理应该如此。