Non-copyable object

This is a discussion on Non-copyable object within the C++ Programming forums, part of the General Programming Boards category; Is this how I would make an object non-copyable: Code: class Node{ public: T data; Node *next, *prev; Node(const T& ...

  1. #1
    Registered Abuser
    Join Date
    Sep 2007
    Location
    USA/NJ/TRENTON
    Posts
    127

    Non-copyable object

    Is this how I would make an object non-copyable:
    Code:
    class Node{
                
                public:
                
                    T data;
                    Node *next, *prev;
                    Node(const T& d, Node* n = 0, Node* p = 0) : data(d), next(n), prev(p) {};
                
                private:
                    
                    Node(const Node& rhs_n) : data(rhs_n.data), next(rhs_n.next), prev(rhs_n.prev) {};
                    Node& operator=(const Node& rhs_n){
                        
                        data = rhs_n.data;
                        next = rhs_n.next;
                        prev = rhs_n.prev;
                        return *this;
                    };
            };
    ????

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    Well, yes. If the operator = and copy constructor is private, then no one can copy it. You don't need to implememt the functions, however.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using this as synchronization object
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 03-22-2008, 07:49 AM
  2. circular doubly linked list help
    By gunnerz in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 08:38 PM
  3. Replies: 60
    Last Post: 12-20-2005, 10:36 PM
  4. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  5. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21