copy constructor basic

Discussion in 'C++' started by kathy, Feb 16, 2011.

  1. kathy

    kathy Guest

    For class:

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

    What "=delete" means?
     
    kathy, Feb 16, 2011
    #1
    1. Advertising

  2. Juha Nieminen, Feb 16, 2011
    #2
    1. Advertising

  3. On Feb 16, 6:32 pm, kathy <> wrote:
    > 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
     
    Saeed Amrollahi, Feb 16, 2011
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VisionSet
    Replies:
    8
    Views:
    4,927
    Tris Orendorff
    Apr 29, 2004
  2. Aire
    Replies:
    3
    Views:
    474
    Mike Wahler
    Jan 25, 2004
  3. ali
    Replies:
    4
    Views:
    590
    David Harmon
    Mar 5, 2007
  4. Generic Usenet Account
    Replies:
    10
    Views:
    2,282
  5. cinsk
    Replies:
    35
    Views:
    2,653
    James Kanze
    Oct 11, 2010
Loading...

Share This Page