Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Be careful about breaking the Concrete Data Type idiom.</strong></p> <p>You are trying to circumvent the fact that the <code>new</code> operator has been made private, i.e. the <code>Concrete Data Type</code> idiom/pattern. The <code>new</code> operator was probably made private for specific reasons, e.g. another part of the design may depend on this restriction. Trying to get around this to dynamically allocate an instance of the class is trying to circumvent the design and may cause other problems or other unexpected behavior. I wouldn't suggest trying to circumvent this without studying the code thoroughly to ensure you understand the impact to other parts of the class/code.</p> <h1>Concrete Data Type</h1> <ul> <li><a href="http://users.rcn.com/jcoplien/Patterns/C++Idioms/EuroPLoP98.html#ConcreteDataType" rel="nofollow">http://users.rcn.com/jcoplien/Patterns/C++Idioms/EuroPLoP98.html#ConcreteDataType</a></li> </ul> <blockquote> <p><strong>Solutions</strong></p> <p>...</p> <p>Objects that represent abstractions that live "inside" the program, closely tied to the computational model, the implementation, or the programming language, should be declared as local (automatic or static) instances or as member instances. Collection classes (string, list, set) are examples of this kind of abstraction (though they may use heap data, they themselves are not heap objects). They are concrete data types--they aren't "abstract," but are as concrete as int and double.</p> </blockquote> <pre><code>class ScopedLock { private: static void * operator new (unsigned int size); // Disallow dynamic allocation static void * operator new (unsigned int size, void * mem); // Disallow placement new as well. }; int main (void) { ScopedLock s; // Allowed ScopedLock * sl = new ScopedLock (); // Standard new and nothrow new are not allowed. void * buf = ::operator new (sizeof (ScopedLock)); ScopedLock * s2 = new(buf) ScopedLock; // Placement new is also not allowed } </code></pre> <blockquote> <p>ScopedLock object can't be allocated dynamically with standard uses of new operator, nothrow new, and the placement new.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload