blob: 5c604404fc06bc535c95e7af829523a6dbc84fb1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include <meowpp/debug/assert.h>
#include <meowpp/utility/object.h>
#include <meowpp/utility/object.h>
#include <meowpp/utility/object.h>
static bool destructor_be_called = false;
class A : public meow::Object {
public:
~A() {
destructor_be_called = true;
}
} _;
class B : public meow::Object {
public:
meow::Object* Copy() const {
return static_cast<meow::Object*>(&_);
}
bool Equals(meow::Object const* b) const {
return false;;
}
meow::Object* CopyFrom(meow::Object const* ptr) {
return const_cast<meow::Object*>(ptr);
}
};
int main() {
meow::Object* ptr = new A, *ptr2 = new B;
delete ptr;
if (!destructor_be_called) {
return 1;
}
ptr = new A;
Assert(ptr->Copy() == NULL, "");
Assert(ptr->Equals(NULL) == false, "");
Assert(ptr->CopyFrom(ptr2) == NULL, "");
ptr = new B;
Assert(ptr->Copy() == &_, "");
Assert(ptr->Equals(NULL) == false, "");
Assert(ptr->CopyFrom(ptr2) == ptr2, "");
////////////////////////////////////////
return 0;
}
|