开始学习QT第一步C++,Qt界面字体和代码风格调整

一、使用版本为Qt5.11.1,代码字体为 Consolas

1、结构体

#include <iostream>
#include <string.h>

using namespace std;

struct Name
{
    int age;
    int name[];
    int *arr;
};

int main()
{
    Name my;//结构体生成对象,
    my.age=19;

    my.name[0]=100; //或者使用字符串拷贝操作 strcpy(my.name,"admin")

    int value=28;
    my.arr=&value; //将arr指向一个整型变量的地址

    cout << my.age << endl;
    cout << my.name[0] << endl;
    cout << *(my.arr) << endl;

    return 0;
}

2、类

#include <iostream>
#include <string.h>

using namespace std;

class father
{
public:
    char name[64];
    int age;
    char sex;
    void test();//普通函数

    virtual void test01();//必须要在父类中实现一个默认功能否则会报错

    virtual void sumber(int a,int b)=0; //★★★★★拥有纯虚函数的类叫抽象类,
                                        //并且无法实例化对象,就是说在主函数中无法使用这个类
};

class son:public father //继承的使用方法
{
public:
    int add;
    void test01()//由于是虚函数,子类会覆盖掉父类的内容
    {
        cout<<"son_test01()"<<endl;
    }
    void sumber(int a,int b) //纯虚函数,只能在子类实现
    {
        int sum=a+b;
        cout<<sum<<endl;
    }
};


int main()
{
//    father my;//在栈中生成对象my  通过使用 . 访问
//    my.name[0]='A';//或者使用strcpy(my.name,"ABC");
//    my.age=19;
//    my.sex='B';
//    my.test();//访问方式都是一样的

//    father *myfather=new father;//在堆中生成一个对象 myfather 通过使用 -> 访问
//    myfather->name[0]='c';//或者使用strcpy(myfather->name,"abc");
//    myfather->age=18;
//    myfather->sex='a';
//    myfather->test();
//    myfather->test01();

    son myDad;
    myDad.test01();
    myDad.age=100;

    son *mySon=new son;
    mySon->add=100;
    mySon->age=200;

    mySon->sumber(3, 4); // 调用纯虚函数sumber

//    delete myfather;
    delete mySon;

    return 0;
}

void father::test()//father::是标记使用的这个类里面的函数,同时可以在类内实现函数功能
{
    cout<<"output test()"<<endl;
}

void father::test01()//虚函数实现
{
    cout<<"output virtual test01()"<<endl;
}

二、代码编辑界面设置

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值