类和对象运用知识点

一.auto

作用:auto可自动转换成相应的类型,可运用于函数,变量等

例:auto a=1;auto自动转换为int类型

auto b=1.1;auto自动转换为double类型

auto c=&a;auto自动转换为int*类型

二.typeid

作用:typeid给出auto的类型

例:auto a=b;

auto c='a';

auto d=testAuto();

cout<<typeid(a)<<endl;

cout<<typeid(c)<<endl;

cout<<typeid(d)<<endl;

三.C++11范围for

定义数组后

1.在平常c语言学习中我们循环写成

for(int i=0;i<n;i++)

{

        printf("%d",arr[i]);

}

2.而在循环for中可以写成

for(auto e:array)

{

cout<<e<<" "<<endl;

}

四.nullptr

在C语言中我们指针用NULL表示空指针,但在C++中NULL同时也代表着0两者容易混淆,所以在C++中我们用nullptr代替NULL

五.class

class用于类的封装而且相对于namespace封装class有public,private,projected可以更好的用于区分和服务

六.this指针

this指针是在class类里面成员函数特有的指针

例:class Date

{

        public;

        Date(int year,int month,int day)

        {

                _year=year;

                _month=month;

                _day=day;

        }

        private:

        int _year;

        int _month;

        int _day;

};在此构造函数Date中_year=year完整是this->_year=year,this->month=month;this_day=day;

this指针是在成员函数中指向成员变量的指针。

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值