#include <iostream>
#include <vector>
void Test1()
{
int a = 10;
int b = 20;
int *p = &a;
std::cout<<p<<","<<*p<<std::endl;
p = &b;
std::cout<<p<<","<<*p<<std::endl;
int *np ;
int &r = a;
std::cout<<a<<std::endl;
r = b;
std::cout<<a<<std::endl;
}
void Test2()
{
std::vector<int> v(3,0);
for (auto it: v) {
std::cout<<it<<std::endl;
}
v[0] = 10;
v[1] = 20;
v[2] = 30;
for (auto it: v) {
std::cout<<it<<std::endl;
}
}
class Test{
public:
Test(int id):m_id(id){
std::cout<<"constructor"<<std::endl;
}
Test(const Test& t):m_id(t.m_id){
std::cout<<"copy constructor"<<std::endl;
}
~Test(){
std::cout<<"destructor"<<std::endl;
}
int m_id;
};
void TestParamCopy(const Test r){
}
void TestParamRefer(const Test& r){
}
void Test3()
{
Test t(2);
TestParamCopy(t);
TestParamRefer(t);
}
int main()
{
Test1();
Test2();
Test3();
return 0;
}
|