C ++
我这样简单的代码:
#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;
}
但编译错误:
a.cpp:在函数'int main()'中:a.cpp:7:60:错误:没有匹配函数调用'atomic_is_lock_free(std :: shared_ptr *)'std :: cout << std :: boolalpha < <std :: atomic_is_lock_free(&p)<< std :: endl; ^ a.cpp:7:60:注意:候选项是:从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:注意:'std :: shared_ptr'不是从'const std :: atomic <_ITp>'std :: cout << std :: boolalpha << std :: atomic_is_lock_free(&p)< <std :: endl; ^从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'不是从'const volatile std :: atomic <_ITp>'std :: cout << std :: boolalpha << std :: atomic_is_lock_free(&p)<< std :: endl;
没有template <class T> bool atomic_is_lock_free( const std::shared_ptr<T>* p );
超载。 就像这里所说的那样。 我的代码必须有错误,有人可以帮我吗? 谢谢!
上一篇: c++