#851 closed defect (fixed)
Use delete on noncopyable classes
Reported by: | cvvergara | Owned by: | strk |
---|---|---|---|
Priority: | trivial | Milestone: | 3.7.0 |
Component: | Core | Version: | 3.6.2 |
Severity: | Unassigned | Keywords: | |
Cc: |
Description
C++11
When the copy construction and assignment wants to be explicitly forbidden by the author, it needs to have the = delete
Current code looks like:
// Declare type as noncopyable RayCrossingCounter(const RayCrossingCounter& other); RayCrossingCounter& operator=(const RayCrossingCounter& rhs);
(1) If it is used externally, it will be a compiler error (because it is private). (expected)
(2) But if it is referenced internally or by a friend, then it will produce a link error because the definition does not exist.
In C++11:
// Declare type as noncopyable RayCrossingCounter(const RayCrossingCounter& other) = delete; RayCrossingCounter& operator=(const RayCrossingCounter& rhs) = delete;
Here, (2) the compiler will note this at compilation - no linker errors and clear intent.
Change History (5)
comment:1 by , 6 years ago
comment:2 by , 6 years ago
Milestone: | 3.6.3 → 3.7.0 |
---|
comment:3 by , 6 years ago
As far as I know = delete starts from C++11
http://en.cppreference.com/w/cpp/language/default_constructor
comment:4 by , 6 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:5 by , 6 years ago
@cvvergara Next time, can you try in the commit putting in
Closes #whatever_the_ticket_number in the git commit message.
It should automatically reference back to the ticket with the git ref. and close the ticket automatically.
is this same behavior for lower than C++11?
Note 3.7+ hasn't been released yet so we can standardize on C++11 if we want to.
3.6+ has to work for lower. Anyway this should probably go in 3.7 and not lower, so switching milestone.