8

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?

Dada
  • 6,313
  • 7
  • 24
  • 43
Roey Lehman
  • 356
  • 1
  • 3
  • 16
  • 2
    Well, it sounds like you've attempted to use (call or take the address of) a deleted function but if you don't want to post the code you're unlikely to be able to get much more help than is in the error message that you've posted. – CB Bailey Apr 09 '12 at 21:32
  • 1
    Well , you've basically answered my question with my question. I know I've attempted to use a deleted function. The error told me that. but what is a deleted function? – Roey Lehman Apr 10 '12 at 08:57
  • That was my point. Without more context - the code - all that we can do is rephrase the error message. If you don't know what a deleted function is then ask that as a question. – CB Bailey Apr 10 '12 at 09:13
  • 1
    I don't mean to troll, but as you can see the poster below has given me an answer which satisfied me. So I guess you could've given me one too.. – Roey Lehman Apr 10 '12 at 17:34
  • Without more information you're question is not answerable, IMHO. I am happy that you are satisfied with the answer that you've been given. Why should I provide another answer? What am I supposed to put in it that you would benefit from? I am confused. – CB Bailey Apr 10 '12 at 17:43

5 Answers5

19

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.

Carlos Molinero
  • 191
  • 1
  • 3
6

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.

user2891659
  • 121
  • 1
  • 9
4

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.

bames53
  • 86,085
  • 15
  • 179
  • 244
1

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

bubakazouba
  • 1,633
  • 2
  • 22
  • 34
0

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.

sondrelv
  • 111
  • 2
  • 6