xcode - “attempt to use a deleted function” - what does that mean?

孤街醉人 提交于 2019-12-04 03:28:42

问题


I am writing a C++ library in Xcode 4.2

One of my classes won't compile with this error : "attempt to use a deleted function".

There is no specific indication what function it's talking about. I don't want to post the class code here, but does anybody have any idea what this error means? It's nowhere to be found on Google... :(

thanks a bunch

Roey


回答1:


In C++11 you can declare functions as deleted:

struct Foo {
    Foo(const Foo &) = delete;
};

Attempting to use such a function is an error. The purpose of doing this is so that, in this example, copy construction of this type is not possible. This is a more direct replacement for the non-copyable trick used pre-C++11.

Also, there are rules in the C++ spec that lead to member functions being implicitly deleted.

The error is telling you that your program attempts to use a deleted function. You'll have to post the error you're getting for more detailed help.




回答2:


I had a similar message with threads (C++11). It turned out that I was passing the wrong number of parameters to the function called by the thread so the thread did not find any function suitable and gave that message.




回答3:


To add to Carlos' answer, I had the right number of arguments but one of the arguments was being passed by reference. Adding ref() around the variable fixed it for me. See here.




回答4:


For me It solved it when I passed "this" pointer as a parameter to the function.




回答5:


For me, the issue was that one of the arguments was a pointer, and I passed NULL directly as an argument. To solve this, I simply created a new NULL pointer which I passed to the function as an l-value instead.



来源:https://stackoverflow.com/questions/10080102/xcode-attempt-to-use-a-deleted-function-what-does-that-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!