Skip to content

Commit 39994bb

Browse files
committed
C++11-ify NonCopyable
Define copy operators public and deleted rather declaring them private and undefined. Will give immediate compilation errors rather than delayed linking errors.
1 parent aa6fd58 commit 39994bb

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

platform/NonCopyable.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,12 @@ namespace mbed {
9191
* in the base declaration.
9292
*
9393
* To solve that problem, the copy constructor and assignment operator have to
94-
* be declared (but don't need to be defined) in the private section of the
95-
* Connection class:
94+
* be declared as deleted:
9695
*
9796
* @code
9897
* struct Connection {
99-
* private:
100-
* Connection(const Connection&);
101-
* Connection& operator=(const Connection&);
98+
* Connection(const Connection &) = delete;
99+
* Connection &operator=(const Connection &) = delete;
102100
* }
103101
* @endcode
104102
*
@@ -211,18 +209,17 @@ class NonCopyable {
211209
}
212210

213211
#else
214-
private:
215212
/**
216213
* Declare copy constructor as private. Any attempt to copy construct
217214
* a NonCopyable will fail at compile time.
218215
*/
219-
NonCopyable(const NonCopyable &);
216+
NonCopyable(const NonCopyable &) = delete;
220217

221218
/**
222219
* Declare copy assignment operator as private. Any attempt to copy assign
223220
* a NonCopyable will fail at compile time.
224221
*/
225-
NonCopyable &operator=(const NonCopyable &);
222+
NonCopyable &operator=(const NonCopyable &) = delete;
226223
#endif
227224
#endif
228225
};

0 commit comments

Comments
 (0)