首页 > 编程语言 >C++ 在函数内部输出当前类名方式

C++ 在函数内部输出当前类名方式

时间:2023-05-31 12:00:09浏览次数:31  
标签:函数 Car void move C++ virtual 类名

开发环境:QtCreator  C++

 1 using namespace std;
 2 
 3 /* 基类汽车 */
 4 class Car
 5 {
 6 public:
 7     Car()     {}
 8     virtual ~Car()    {}
 9     virtual void move(void);
10 };
11 
12 /* 基本属性汽车运动 */
13 void Car::move(void)
14 {
15     cout << __PRETTY_FUNCTION__ << endl; 
16     cout << typeid(*this).name() << endl; 
17 }
18 
19 class CarSmall : public Car
20 {
21 public:
22     CarSmall()  {}
23     ~CarSmall() {}
24     
25     void move(void) override ;
26     
27 };
28 
29 void CarSmall::move(void)
30 {
31     cout << __PRETTY_FUNCTION__ << endl; 
32     cout << typeid(*this).name() << endl; 
33 }
34 
35 int main()
36 {
37     cout << "Hello World!" << endl;
38     cout << __PRETTY_FUNCTION__ << endl; 
39     
40     Car car;
41     car.move();
42     
43     CarSmall carSmall;
44     carSmall.move();
45     
46     return 0;
47 }

编译输出:

 

标签:函数,Car,void,move,C++,virtual,类名
From: https://www.cnblogs.com/yangjinghui/p/17445738.html

相关文章

  • < Python全景系列-9 > Python 装饰器:优雅地增强你的函数和类
    欢迎来到我们的系列博客《Python全景系列》第九篇!在这个系列中,我们将带领你从Python的基础知识开始,一步步深入到高级话题,帮助你掌握这门强大而灵活的编程语法。无论你是编程新手,还是有一定基础的开发者,这个系列都将提供你需要的知识和技能。**装饰器在Python中扮演了重要的角......
  • C++多态虚函数表详解(多重继承、多继承情况)
    本文关键词:C++多态多继承多重继承虚函数表虚函数指针动态绑定概述:C++相对其他面向对象语言来说,之所以灵活、高效。很大程度的占比在于其多态技术和模板技术。C++虚函数表是支撑C++多态的重要技术,它是C++动态绑定技术的核心。本文章将着重图解虚函数表相关知识,在阅读本文......
  • c++中的析构函数和纯虚函数
    析构函数:c++中当delete一个类对象时,会默认调用其析构函数,析构函数的作用就是释放对象占用的堆空间。一般基类的析构函数需写成虚函数,这是因为在多态下,我们一般用基类的指针来指向一个子类对象,若基类的虚函数未被重写,那么可能会造成内存泄漏。因此需要在子类重写基类的虚函数来......
  • 【c&c++】erase怎么用c语言,C++ erase()函数使用时的注意点
    遇见的场景删除vector容器指定元素时;erase()函数的用法vector::erase():从指定容器删除指定位置的元素或某段范围内的元素。具体用法如下:iteratorerase(iterator_Where);删除指定位置的元素,返回值是一个迭代器,指向删除元素的下一个元素;iteratorerase(iterator_First,i......
  • ZOJ - 4069(2018 青岛现场赛 L) - 指数型生成函数
    题目链接:https://vjudge.net/problem/ZOJ-4069 解题思路:1.n个点组成环的不同种类数是(n-1)!/2;n个点组成一条链的不同种类数是n!/2,特别的n==1时种类数为1。用指数型生成函数表示k个点形成链的种类:1/2(2x+2!*x^2/2!+3!*x^3/3!+4!*x^4/4!+..+n!*x^n/n!)=1/2(2*x+x^2+x^3+x^4+......
  • BDB c++例子,从源码编译到运行
    第一步先下载源码,解压后./dist/configure--enable-cxx编译,然后make,makeinstall--enable-cxxTobuildtheBerkeleyDBC++API,enter--enable-cxxasanargumenttoconfigure. 默认的安装路径是:/usr/local/BerkeleyDB.6.1/ 代码如下:#include<stdlib.h>#include<strin......
  • MongoDB C++ gridfs worked example
    使用libmongoc,参考:http://mongoc.org/libmongoc/current/mongoc_gridfs_t.html#include<mongoc.h>#include<stdio.h>#include<stdlib.h>#include<fcntl.h>classMongoGridFS{public:MongoGridFS(constchar*db);~MongoGridFS();......
  • cassandra cpp driver中bind list——用cass_statement_bind_collection函数
     CassErrorinsert_into_collections(CassSession*session,constchar*key,constchar*items[]){CassErrorrc=CASS_OK;CassStatement*statement=NULL;CassFuture*future=NULL;CassCollection*collection=NULL;constchar**item=NULL;c......
  • mongodb c++ driver安装踩坑记
     安装教程:https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/(1)“initializer_list”filenotfoundhttp://stackoverflow.com/questions/19493671/initializer-list-no-such-file-or-directorySinceyouareusing GCC-4.8 andyourproblemisthatyoud......
  • 单链表(c++实现)
    template<typenameT>classListNode{public:explicitListNode(Tvalue_,ListNode*next_=nullptr):value(value_),next(next_){}TgetValue()const{returnvalue;}ListNode<T>*getNext()const{returnnext;};voidsetNext(ListNo......