Sponsored Content
Top Forums Programming About uncopyable class (on book:Effective C++) Post 302738455 by Corona688 on Saturday 1st of December 2012 12:40:34 PM
Old 12-01-2012
A copy constructor's not going to get called unless you copy it. Your Dog(const Dog &rhs) constructor does literally nothing -- it's not even going to copy Dog, and passes nothing into Uncopyable. Lacking any other information, the compiler uses the default.

Last edited by Corona688; 12-01-2012 at 01:45 PM..
 

9 More Discussions You Might Find Interesting

1. Cybersecurity

Changing effective user

I would like to give execution rights for a script to one user. (that's the easy part...) When that user is running the script, I would like the effective user ID to be that of the file-owner. Is this possible? (6 Replies)
Discussion started by: hilmel
6 Replies

2. UNIX for Dummies Questions & Answers

most effective search ?

what's the most efficient and effective search for a file in a dir ? I see many guys use this # find - print or something as such ? and sometimes pipe it to something else ? Is there a better way of using "grep" in all of this ? thanks simon2000 (3 Replies)
Discussion started by: simon2000
3 Replies

3. UNIX for Dummies Questions & Answers

car class (not school class)

im just trying to have some fun and kill some time writing a c++ program that has a person type in a car make and model then gives them a year and a price. or something like that. i always have problems getting it goin but once the ball is rolling im usually pretty good. anyone wanna help me out? ... (1 Reply)
Discussion started by: rickym2626
1 Replies

4. Programming

C++ class definition with a member of the same class

Hi, i have a question about C++. Is it possible to declare a class with a member ot the same class? For example, a linked list or i want to convert this C code to C++ class (Elemento) typedef struct elemento { char name; char value; List<struct elemento> ltElementos; ... (7 Replies)
Discussion started by: pogdorica
7 Replies

5. UNIX for Dummies Questions & Answers

Real and Effective IDs

Can anyone explain me in details of Real and Effective IDs (6 Replies)
Discussion started by: kkalyan
6 Replies

6. Programming

static use for class inside the same class c++

Hi, I believe the next code is wrong: class Egg { Egg e; int i; Egg(int ii=0) : i(ii) {} }; because you would end up with an endless definition (memory allocation) of Egg objects, thus int i. Ok, so God Eckel proposes for a singleton: class Egg { static Egg e; int... (5 Replies)
Discussion started by: xavipoes
5 Replies

7. UNIX for Advanced & Expert Users

Get pointer for existing device class (struct class) in Linux kernel module

Hi all! I am trying to register a device in an existing device class, but I am having trouble getting the pointer to an existing class. I can create a class in a module, get the pointer to it and then use it to register the device with: *cl = class_create(THIS_MODULE, className);... (0 Replies)
Discussion started by: hdaniel@ualg.pt
0 Replies

8. Programming

Size of Derived class, upon virtual base class inheritance

I have the two class definition as follows. class A { public: int a; }; class B : virtual public A{ }; The size of class A is shown as 4, and size of class B is shown as 16. Why is this effect ?. (2 Replies)
Discussion started by: techmonk
2 Replies

9. Programming

C++ : Base class member function not accessible from derived class

Hello All, I am a learner in C++. I was testing my inheritance knowledge with following piece of code. #include <iostream> using namespace std; class base { public : void display() { cout << "In base display()" << endl; } void display(int k) {... (2 Replies)
Discussion started by: anand.shah
2 Replies
smart_pointer(7rheolef) 					    rheolef-6.1 					   smart_pointer(7rheolef)

NAME
smart_pointer, smart_pointer_clone - reference counted safe pointer with true copy semantic DESCRIPTION
Here is a convenient way to implement a true copy semantic, by using shallow copies and reference counting, in order to minimise memory copies. This concept is generally related to the smart pointer method for managing memory. The true semantic copy is defined as follows: if an object A is assigned to B, such as A = B, every further modification on A or B does not modify the other. Notice that this class differs from the boost::shared_ptr class that implements safe pointers without the true copy semantic. CLONE VARIANT
The smart_pointer_clone variant uses a T* T::clone() const member function instead of the usual T::T() copy constructor for obtaining a true copy of the data. This variant is motivated as follows: when using hierarchies of derived classes (also known as polymorphic classes), the usual copy is not possible because c++ copy constructors cannot be virtual, so you cannot make a copy this way. This is a well-known problem with C++'s implementation of polymorphism. We uses a solution to the non-virtual copy constructor problem which is suggested by Ellis and Stroustrup in "The Annotated LRM". The solution is to require the T class to provide a virtual clone method for every class which makes a copy using new and the correct copy con- structor, returning the result as a pointer to the superclass T. Each subclass of T overloads this function with its own variant which copies its own type. Thus the copy operation is now virtual and furthermore is localised to the individual subclass. NOCOPY VARIANT
This variant of the smart pointer is designed for use on objects that cannot (or must not) be copied. An example would be when managing an object that contains, say, a file handle. It is essential that this not be copied because then you get the problem of deciding which copy is responsible for closing the file. To avoid the problem, wrap the file handle in a class and then manage a unique instance of it using a smart_pointer_nocopy. This ensures that the file handle cannot be copied and is closed when the last alias is destroyed. The interface to the nocopy variant is the same as smart_pointer but with all operations that perform copying forbidden. In fact, because all three variants are instances of a common superclass, the forbidden methods do exist but will cause an error and exit if they are called. The following modifiers cannot be used because they use copying of the pointed-to object and will thereore cause an error: T* operator-> (); T& operator* (); T* pointer (); T& data (); EFERENCES
[1] A. Geron and F. Tawbi, Pour mieux developper avec C++ : design pattern, STL, RTTI et smart pointers, InterEditions, 1999. Page 118. [2] STLplus, http://stlplus.sourceforge.net/stlplus3/docs/smart_ptr.html for the clone and nocopy variants. IMPLEMENTATION
template <class T, class C> class smart_pointer_base { public: // allocators: smart_pointer_base (T* p = 0); smart_pointer_base (const smart_pointer_base<T,C>&); smart_pointer_base<T,C>& operator= (const smart_pointer_base<T,C>&); ~smart_pointer_base (); // accessors: const T* pointer () const; const T& data () const; const T* operator-> () const; const T& operator* () const; // modifiers: T* pointer (); T& data (); T* operator-> (); T& operator* (); // implementation: private: struct counter { T* _p; int _n; counter (T* p = 0); ~counter (); int operator++ (); int operator-- (); }; counter *_count; #ifndef TO_CLEAN public: int reference_counter() const { return _count != 0 ? _count->_n : -1; } #endif // TO_CLEAN }; rheolef-6.1 rheolef-6.1 smart_pointer(7rheolef)
All times are GMT -4. The time now is 03:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy