mirror of
https://github.com/changkun/modern-cpp-tutorial.git
synced 2025-12-17 12:44:40 +03:00
prepare for c++17
This commit is contained in:
28
code/5/5.3.cpp
Normal file
28
code/5/5.3.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
class A;
|
||||
class B;
|
||||
|
||||
class A {
|
||||
public:
|
||||
std::shared_ptr<B> pointer;
|
||||
~A() {
|
||||
std::cout << "A 被销毁" << std::endl;
|
||||
}
|
||||
};
|
||||
class B {
|
||||
public:
|
||||
std::shared_ptr<A> pointer;
|
||||
~B() {
|
||||
std::cout << "B 被销毁" << std::endl;
|
||||
}
|
||||
};
|
||||
int main() {
|
||||
std::shared_ptr<A> a = std::make_shared<A>();
|
||||
std::shared_ptr<B> b = std::make_shared<B>();
|
||||
a->pointer = b;
|
||||
b->pointer = a;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user