代码拉取完成,页面将自动刷新
#include <iostream>
#include "SharePtr.h"
#include <vector>
#include <Windows.h>
using namespace std;
class A
{
public:
A()
{
cout << "init" << endl;
}
~A()
{
cout << "destory" << endl;
}
};
class B
{
public:
B(int a)
{
cout << "init b " << a << endl;
}
~B()
{
cout << "destory b " << endl;
}
};
class Base
{
public:
Base() { cout << "init base" << endl; }
virtual ~Base() { cout << "destory base" << endl; }
void basePrintf()
{
cout << __FUNCTION__ << endl;
}
virtual void printf()
{
cout << __FUNCTION__ "Base"<< endl;
}
};
class Test
:public Base
{
public:
Test() { cout << "int Test" << endl; }
virtual ~Test() { cout << "destory Test " << endl; }
void TestPrintf()
{
cout << __FUNCTION__ << endl;
}
void printf()
{
cout << __FUNCTION__ "test" << endl;
}
};
void func()
{
SharePtr<Base> p = staticPointerCast<Base>(makeSharePtr<Test>());
p->basePrintf();
p->printf();
SharePtr<Test> t = dynamicPointerCast<Test>(p);
if (t != nullptr)
{
t->TestPrintf();
p->printf();
}
}
void run(SharePtr<Base> v)
{
while (true)
{
Sleep(100);
}
}
int main()
{
func();
vector<SharePtr<Base>> ver;
ver.push_back(staticPointerCast<Base>(makeSharePtr<Test>()));
SharePtr<Base> p = makeSharePtr<Base>();
ver.push_back(p);
ver.clear();
p.reset();
const SharePtr<Base> v = makeSharePtr<Base>();
SharePtr<Base> b = constPointerCast<Base>(v);
b->basePrintf();
run(p);
//std::make_shared()
// std::static_pointer_cast<>
/*SharePtr<A> p(new A());
std::vector<SharePtr<A>> ver;
ver.push_back(p);
ver.push_back(SharePtr<A>(new A()));
ver.clear();
SharePtr<A> pp = makeSharePtr<A>();
func();
SharePtr<B> pb = makeSharePtr<B>(123);
cout << "----------" << endl;
*/
system("pause");
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。