0

我有一个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'

我真的不明白为什么它试图链接到 volatile 重载store(),在源代码中指向成员函数的指针是const,而不是volatile(并且它编译)。

相同的代码用 g++ 4.6.3 编译

4

1 回答 1

3

很简单:GCC 4.4 不支持这个,或者它在你经历的方式中被破坏了。较新的 GCC 有更好的支持,并且它应该像它应该的那样工作。

于 2012-06-25T11:20:50.810 回答