第二题P3-4

#include<vector>
#include<iostream>
struct B {
	int m = 0;
	void hello() const {
		std::cout <<"Hello world, this is B!\n";
	}
};
struct D : B {
	void hello() const {
		std::cout << "Hello world, this is D!\n";
	}
};
enum class E { ONE = 1,TWO,THREE };
enum EU { ONE = 1,TWO,THREE };

int main()
{
	int n = static_cast<int>(3.14);
	std::cout<<"n = "<<n<<'\n';
	std::vector<int> v = static_cast<std::vector<int>>(10);
	std::cout << "v.size() = "<<v.size()<<'\n';
	D d;
	B& br = d;
	br.hello();
	D& another_d = static_cast<D&>(br);
	another_d.hello();
	std::vector<int> v2 = static_cast<std::vector<int>&&>(v);
	std::cout<<"after move,v.size() = "<<v.size()<<'\n';
	static_cast<void>(v2.size());
	void* nv = &n;
	int* ni = static_cast<int*>(nv);
	std::cout << "*ni = "<<*ni<<'\n';
	D a[10];
	B* dp = static_cast<B*>(a);
	E e = E::ONE;
	int one = static_cast<int>(e);
	std::cout<<one<<'\n';
	E e2 = static_cast<E>(one);
	EU eu = static_cast<EU>(e2);
	int D::*pm = &D::m;
	std::cout<<br.*static_cast<int B::*>(pm)<<'\n';
	void* voidp = &e;
	std::vector<int>* p = static_cast<std::vector<int>*>(voidp);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值