# C/++/# Explain this line "thread& operator = (const thread&) = delete;"

#### NotASmurf

here delete, thread, and const are obviously keywords, I saw this when the system libraries threw a breakpoint, not my code, I'm new at this and that line of code makes very little sense to me, afaik, (const thread&) should be a conversion operator, how can you set an operator to a statement? then set a variable to that?

Related Programming and Computer Science News on Phys.org

#### jedishrfu

Mentor
It may be typing the variable as in
Java:
float y = 3.0;

int x = (int ) y;

#### jedishrfu

Mentor
What programming language is it?

it's c++

#### pasmith

Homework Helper
here delete, thread, and const are obviously keywords, I saw this when the system libraries threw a breakpoint, not my code, I'm new at this and that line of code makes very little sense to me, afaik, (const thread&) should be a conversion operator, how can you set an operator to a statement? then set a variable to that?
Without the "= delete" this would be a function declaration, overloading the assignment operator for a class called "thread" (it's odd that the class name isn't capitalized).

The "= delete;" part is apparently a new (ie. only introduced in 2011) C++ language feature which should cause the compiler to quit with a "this function is deleted" error: see various answers to this post on stack exchange.

#### Filip Larsen

Gold Member
The line looks like its from the standard thread library and it has the effect (as mentioned by others) that any default assignment operator that the compiler otherwise will add automatically are deleted (i.e. made not available). In this particular case the thread library uses delete (also on the copy constructor) because otherwise the compiler will add a default copy constructor and copy operator which makes no sense for threads. Note that the corresponding move constructor and assignment operator is defined.

#### newjerseyrunner

C++ can look pretty strange when it comes to operator overloading and function pointers.

The first part: thread & operator = (const thread &) refers to the assignment operator for a thread. It is what will be called if you do something like this.

Code:
thread t1;
t1 = t2;  //The assignment operator is called here
The second part is assigning this behavior to be the same as the "delete" operator for the thread class.

#### Filip Larsen

Gold Member
The second part is assigning this behavior to be the same as the "delete" operator for the thread class.
That is not correct. The "=delete" part declares the method as a deleted function, as mentioned several times already in this thread. Deleted functions are not to be confused with the delete operator.

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving