编辑代码

#include <iostream>
using namespace std;
class Tst2 {
    int x;
    public:
    Tst2(int a){x=a;};
};
class Tst {
    public:
    //variable member
    const int & a;
    Tst2 obj;
    //constructor:
    Tst(int & x):a(x),obj(5){
        // in constructor:
        // you can't assign a constant once declared, a = 5
        // you can't run member's constructor of class once obj is declared, obj(3)
        // :list do things that you can't at here.
        };
    Tst(int const & x):a(x),obj(5){};
    Tst():a(1),obj(5){};
};

int main() {

    int x(1);
    const int b(5);

    // int const & c = 7;
    // cout << c << endl;

    // Tst t1(x);
    // cout << t1.a << endl; 
    // cout << t1.a << endl;

    Tst t2(2);
    cout << t2.a << endl; 
    cout << t2.a << endl;
    
    // Tst t3;   //run default constructor, not Tst t3();
    // cout << t3.a << endl; 
    // cout << t3.a << endl;
    cout << "gogogo" << endl;
    x=6;
    Tst2 t4(x);
    
    

    cout << t2.a << endl; 
    cout << t2.a << endl;


    // int && z =5;
    // int const & x = 5;

    // int const temp = 5;
    // int const * x = &temp;


	
    
    
	return 0;
}