mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
QL code and tests for C#/C++/JavaScript.
This commit is contained in:
26
cpp/ql/src/Best Practices/RuleOfTwo.cpp
Normal file
26
cpp/ql/src/Best Practices/RuleOfTwo.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
class C {
|
||||
private:
|
||||
Other* other = NULL;
|
||||
public:
|
||||
C(const C& copyFrom) {
|
||||
Other* newOther = new Other();
|
||||
*newOther = copyFrom.other;
|
||||
this->other = newOther;
|
||||
}
|
||||
|
||||
//No operator=, by default will just copy the pointer other, will not create a new object
|
||||
};
|
||||
|
||||
class D {
|
||||
Other* other = NULL;
|
||||
public:
|
||||
D& operator=(D& rhs) {
|
||||
Other* newOther = new Other();
|
||||
*newOther = rhs.other;
|
||||
this->other = newOther;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//No copy constructor, will just copy the pointer other and not create a new object
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user