c++
My simple code like this:
#include <iostream>
#include <atomic>
#include <memory>
int main(void) {
std::shared_ptr<int> p = std::make_shared<int>(5);
std::cout << std::boolalpha << std::atomic_is_lock_free(&p) << std::endl;
return 0;
}
But compile error:
a.cpp: In function 'int main()': a.cpp:7:60: error: no matching function for call to 'atomic_is_lock_free(std::shared_ptr*)' std::cout << std::boolalpha << std::atomic_is_lock_free(&p) << std::endl; ^ a.cpp:7:60: note: candidates are: In file included from a.cpp:2:0: /usr/include/c++/4.8.2/atomic:804:5: note: template bool std::atomic_is_lock_free(const std::atomic<_ITp>*) atomic_is_lock_free(const atomic<_ITp>* __a) noexcept ^ /usr/include/c++/4.8.2/atomic:804:5: note: template argument deduction/substitution failed: a.cpp:7:60: note: 'std::shared_ptr' is not derived from 'const std::atomic<_ITp>' std::cout << std::boolalpha << std::atomic_is_lock_free(&p) << std::endl; ^ In file included from a.cpp:2:0: /usr/include/c++/4.8.2/atomic:809:5: note: template bool std::atomic_is_lock_free(const volatile std::atomic<_ITp>*) atomic_is_lock_free(const volatile atomic<_ITp>* __a) noexcept ^ /usr/include/c++/4.8.2/atomic:809:5: note: template argument deduction/substitution failed: a.cpp:7:60: note: 'std::shared_ptr' is not derived from 'const volatile std::atomic<_ITp>' std::cout << std::boolalpha << std::atomic_is_lock_free(&p) << std::endl;
There is no template <class T> bool atomic_is_lock_free( const std::shared_ptr<T>* p );
overload. As here say, there is. There must be a mistake in my code, could anybody help me? Thanks!
上一篇: C ++中的易失性11
下一篇: C ++