Thread: Non-copyable object

  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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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, 11: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