美文网首页
2018-09-26

2018-09-26

作者: 小时候浪死了 | 来源:发表于2018-09-26 22:10 被阅读0次

命名空间

#include<iostream>
using namespace std;
namespace jj01
{
    int a = 10;
}
int main()
{
    cout << jj01::a << endl;
    system("pause");
}

auto(since C++11)

list<string> c;
list<string>::iterator ite;
ite=find(c.begin(),c.end(),target);
//正确:
list<string> c;
auto ite=find(c.begin(),c.end(),target);   //后面推导出前面的类型
//错误:
list<string> c;
auto ite;                                  //推导不出类型
ite=find(c.begin(),c.end(),target);

for(auto elem:vec) //pass by value
{
    cout<<elem<<endl;
}
for(auto& elem:vec) //pass by reference
{
    elem*=3;
}

引用

c++==(附注:java里的变量都是reference)==

int x=0;
int& r=x;
int x2=5;
r=x2;//不能重新代表其他物体

继承

<pre><font size=4>- 构造由内而外base->component->self

  • 析构由外而内self->component->base
  • 纯虚函数不能实例化
  • 所有类的函数都隐藏带有this指针
  • 对象1->函数(&对象1) 哪个对象调用,则this指针就是哪个对象
  • const obiect 不能调用non-const member functions</font></pre>
    静态绑定&&动态绑定
    <pre><font size=4>静态绑定:对象.函数()
    动态绑定:1.向上转型 2.指针 3.虚函数</pre>
    c++内存管理链接

相关文章

网友评论

      本文标题:2018-09-26

      本文链接:https://www.haomeiwen.com/subject/ktxsoftx.html