10.17 C++

1.定义指针的引用:
   

int a = 0;    
int *p;    
p = &a;    
int *&rp = p;    
*rp=5;    
cout << a <<endl;

 

2. 分配 空间

    new //挖坑
    delete //用完
    /*
    C++中 布尔型 : true 和false 是 1 和 0 */

3. string :

    string b;
    b = "hello";
    string c;
    c = " hahah";
    b = b+c;
    cout<<b<<endl;
    /*
    是个类*/

4. 类

class student {  // 其内容被称为类的成员变量
private:  // 不能被改变 和 打印
    int sid;
    int score;
    char gender;
public:  // 公共部分 
    int getsid(){ return sid;}
    int getscore(){ return score;}
    void setsid(int sid){
        this->sid=sid;  // this 是指针 指着运行时当前类中的成员变量
    }
};

5. 构造

为了方便快速给类赋值,可以在public中

#include <iostream>

using namespace std;

class Student    
{
private:  
    int sid;
    int score;
    char gender;
public:  
    Student (int sid,int score, char gender)
    {
        this->sid=sid;
        this->score=score;
        this->gender=gender;
    }
    int getsid()
    {
        return sid;
    }
    int getscore()
    {
        return score;
    }
    void setsid(int sid)
    {
        this->sid=sid;  
    }
};

int main()
{
    Student *p ;
    p = new Student(100,105,'M');
    Student ls(1000,32,'F');
    cout<<p->getsid()<<endl;

    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值