10.17 C++

1.定义指针的引用:
   

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

 

2. 分配 空间

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

3. string :

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

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 

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<getsid()<

 

你可能感兴趣的:(C++学习)