C++测试代码(一)

#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;

 

class BaseClass{
public:
 BaseClass(){};
 ~BaseClass(){};
 void virtual fun1()
 {
  cout << "This is Base Class funtion One." << endl;
  fun2();
  return;
 }
 void fun2()
 {
  cout << "This is Base Class funtion Two." << endl;
  return;
 }

private:
 //int num;
 char name;
};

class DerivedClass : public BaseClass{
public:
 DerivedClass(){};
 ~DerivedClass(){};
 void fun1()
 {
  cout << "This is Derived Class One." << endl;
  fun2();
  BaseClass::fun1();
  return;
 }
 void fun2()
 {
  cout << "This is Derived Class Two" << endl;
  return;
 }
private:
 //char name;
 int num;
};

class SubClass : public DerivedClass{
public:
 static int scroe;
};

class Base{
public:
 Base(){};
 ~Base(){};
 void virtual funtion1(){};
};

class Empty{
public:
 Empty(){}
 ~Empty(){}
};

int main()
{
 cout << "Size of BaseClass : " << sizeof(BaseClass) << endl;
 cout << "Size of DerivedClass : " << sizeof(DerivedClass) << endl;
 cout << "Size of SubClass : " << sizeof(SubClass) << endl;

 cout << "Size of Base : " << sizeof(Base) << endl;
 cout << "Size of Empty : " << sizeof(Empty) << endl;

 system("pause");

 DerivedClass d;
 BaseClass &b = d;
 b.fun1();

 system("pause");

 DerivedClass d2;
 BaseClass *b2 = &d2;
 b2->fun1();

 system("pause");

 DerivedClass d1;
 BaseClass b1 = (DerivedClass)d1;
 b1.fun1();

 system("pause");

 int i = 10;
 const int &ci = i;
 int &mi = i;

 cout << ci << endl;
 cout << mi << endl;
 mi += 1;
 cout << ci << endl;
 cout << mi << endl;

 system("pause");
 return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用VS Code进行C语言测试代码时,您可以按照以下步骤操作: 1. 安装VS Code:前往VS Code官方网站(https://code.visualstudio.com/)下载并安装适合您操作系统的版本。 2. 安装C/C++扩展:在VS Code中,点击左侧的扩展图标(类似四个方块的图标),搜索并安装"C/C++"扩展。这个扩展提供了C语言开发所需的工具和功能。 3. 创建一个新的C文件:在VS Code中,打开一个新的文件,然后将文件保存为以.c为后缀的C源代码文件。例如,您可以将文件保存为"test.c"。 4. 配置编译器:在VS Code中,按下快捷键"Ctrl + Shift + P"打开命令面板,然后输入"task"并选择"Tasks: Configure Task"。选择"Create tasks.json file from template",然后选择"C++"。接下来,在生成的tasks.json文件中,将"command"字段修改为您所使用的C编译器的路径。例如,如果您使用的是GCC编译器,可以将该字段修改为`"command": "gcc"`。 5. 编写测试代码:在打开的C源代码文件中编写您的测试代码。例如,您可以编写一个简单的Hello World程序: ```c #include <stdio.h> int main() { printf("Hello, World!"); return 0; } ``` 6. 编译和运行代码:按下快捷键"Ctrl + Shift + B"编译并运行您的代码。如果一切正常,将在输出窗口中看到程序输出的结果。 这些步骤将帮助您在VS Code中进行C语言测试代码。希望对您有所帮助!如有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值