copy constructor basic

K

kathy

For class:

class Foo
{
public:
Foo();
Foo(Foo const&)=delete;
Foo& operator =(Foo const&)=delete;
}

What "=delete" means?
 
S

Saeed Amrollahi

For class:

class Foo
{
public:
    Foo();
    Foo(Foo const&)=delete;
    Foo& operator =(Foo const&)=delete;

}

What "=delete" means?

Hi Kathy

It's new feature of C++0x called deleted functions. For example
in C++03 if you want to prohibit the copy operations, i.e nobody
can't to copy an object or assign to, you have to declare
these special member functions private:
class Foo {
private:
Foo(const Foo&);
Foo& operator=(const Foo&);
};

Now you can say more explicit using delete keyword.
Closely related to deleted functions are defaulted functions.
class Foo {
Foo() = default;
};
It means, you accepted the default behavior of default
constructor which compiler generates for you.
Such thing is somehow more elaboration.

HTH,
-- Saeed Amrollahi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top