//// Created by pengshuai on 2022年3月24日.//#include<iostream>#include<cstdio>using namespace std;struct Base {int v1{};private:int v3{};public: // 显示声明publicint v2{};static void print(){printf("%s\n","Base hello world");};Base() {cout<<"Base construct"<<endl;};virtual ~Base() {cout<<"Base deconstruct"<<endl;};};typedef struct Base1 {int v1;// private: //error!int v3;public: //显示声明publicint v2;static void print(){printf("%s\n","hello world");};} B;struct Derived:Base {Derived() {cout<<"Derived construct"<<endl;};~Derived() override {cout<<"Derived deconstruct"<<endl;};public:int v2 {};static void print(){printf("%s\n","Derived, hello world!");};};//void Base(){// printf("%s\n","I am Base func");//}//void B() {} //error! 符号 "B" 已经被定义为一个 "struct Base1" 的别名int main() {// Base base{}; // errorstruct Base base{};base.v1=1;// base.v3=2; // errorBase::print();printf("%d\n",base.v1);// printf("%d\n",base.v3); // errorBase *b = new Derived();b->print(); // todo:Base::print() 和 class 有点不一样delete b;return 0;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。