您当前的位置: 首页 >  c++

txwtech

暂无认证

  • 3浏览

    0关注

    813博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

ca43a_demo_c++类型转换运算符_强制类型转换

txwtech 发布时间:2020-02-02 19:01:55 ,浏览量:3

/*ca43a_demo_c++类型转换运算符_强制类型转换 c++与c风格代码示范

显式转换-强制类型转换运算符 为什么要用这种方式?明显的提示方式,提醒类型已经转换 static_cast,cast就是转换,编译时,进行检查提示 dynamic_cast reinterpret_cast const_cast 旧式强制类型转换-传统C风格类型转换 避免使用强制类型转换 RTTI,运行时类型识别 txwtech 错误(活动)    E0144    "const char *" 类型的值不能用于初始化 "char *" 类型的实体    ca43a_demo    C:\Users\TT2018\source\repos\ca43a_demo\ca43a_demo\ca43a_demo.cpp    26 //char *pszString = "Hello World!";     //改成如下两句     char pstr[]= "Hello World!";     char *pszString = pstr;

错误(活动)    E0698    运行时 dynamic_cast 的操作数必须包含多态类类型    ca43a_demo    C:\Users\TT2018\source\repos\ca43a_demo\ca43a_demo\ca43a_demo.cpp    58 CDog* pDog = dynamic_cast(pAnimal); class CAnimal { public:     virtual void Speak() = 0; //做成纯虚函数,虚基类,才可以。

}; */

/*ca43a_demo_c++类型转换运算符_强制类型转换
c++与c风格代码示范

显式转换-强制类型转换运算符
为什么要用这种方式?明显的提示方式,提醒类型已经转换
static_cast,cast就是转换,编译时,进行检查提示
dynamic_cast
reinterpret_cast
const_cast
旧式强制类型转换-传统C风格类型转换
避免使用强制类型转换
RTTI,运行时类型识别
txwtech
错误(活动)	E0144	"const char *" 类型的值不能用于初始化 "char *" 类型的实体	ca43a_demo	C:\Users\TT2018\source\repos\ca43a_demo\ca43a_demo\ca43a_demo.cpp	26
//char *pszString = "Hello World!";
	//改成如下两句
	char pstr[]= "Hello World!";
	char *pszString = pstr;

错误(活动)	E0698	运行时 dynamic_cast 的操作数必须包含多态类类型	ca43a_demo	C:\Users\TT2018\source\repos\ca43a_demo\ca43a_demo\ca43a_demo.cpp	58
CDog* pDog = dynamic_cast(pAnimal);
class CAnimal
{
public:
	virtual void Speak() = 0; //做成纯虚函数,虚基类,才可以。

};
*/
#include 

using namespace std;
class CAnimal
{
public:
	virtual void Speak() = 0;

};
class CCat :public CAnimal
{
public:
	void CatchMice()
	{
		cout             
关注
打赏
1665060526
查看更多评论
0.0879s