-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathtest.cpp
More file actions
34 lines (26 loc) · 942 Bytes
/
test.cpp
File metadata and controls
34 lines (26 loc) · 942 Bytes
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
class Dog {
const char *name;
public:
Dog(const char *name) : name(name) {}
virtual void const print_info() const;
};
class Chihuahua : public Dog {
Dog rival;
public:
Chihuahua(const char *name, const Dog &rival) : Dog(name), rival(rival) {}
const Dog &get_rival() { return rival; }
};
void f(Dog e) { e.print_info(); }
void f_ref(const Dog &e) { e.print_info(); }
void f_ptr(const Dog *e) { e->print_info(); }
void test() {
Dog d1("Rex"); // COMPLIANT
Dog d2("Princess"); // COMPLIANT
Chihuahua c1("Ingenius Balduin von den Koenigswiesen", d2); // COMPLIANT
Dog d3(Chihuahua("Spike", c1)); // NON_COMPLIANT
Dog d4 = c1; // NON_COMPLIANT
f(d1); // COMPLIANT
f(c1); // NON_COMPLIANT
f_ptr(&c1); // COMPLIANT
f_ref(c1); // COMPLIANT
}