美文网首页
11-7&&11-8 C++

11-7&&11-8 C++

作者: 当时光一去不复返时 | 来源:发表于2016-11-12 16:05 被阅读0次

重载函数
默认参数函数

inline 内联函数
相当于宏 节省时间但浪费空间 避免了出站和压栈的时间

重载函数 函数名可以同名,编译器根据实参类型来主动寻找相匹配的函数
可以重名的原因:g++编译前会给函数改名字为 原函数名+形参类型 所以实际上来说还是不可以重名

#include<iostream>
using namespace std;
void test(int a,int b)
{
    cout<<"你好"<<endl;
}
void test(int a)
{
    cout<<"sghire"<<endl;
}
int main()
{
    test(10,12);
    test(12);    
}

递归函数
直接递归
间接递归 一般不怎么用

默认参数
从右向左 依次定义
调用
从左向右 依次调用

类和构造函数
结构体的升级

private 私有的
class 默认私有
类域
class person
{
int id;
int money;
public:
void show();
void test(int a,int b);
};
void person::show()
{
cout<<"id="<<id<<endl<<"money="<<money<<endl;
};
void person::test(int a,int b)
{
id=a;
money=b;
};
整个的就是一个类域
类域大于函数域 ,等于全局函数域

this-> g++编译时会给成员对象加上this->表示当前对象地址
此处sizeof 为1


class test
{
int id;
public :
void show()
{
cout<<"this&="<<(this)<<endl;
cout<<"id="<<id<<endl;
}
};
int main()
{
test t;
cout<<"&t="<<&t<<endl;
t.show();
cout<<sizeof(t)<<endl;
}
—————————————————————————————————

相关文章

网友评论

      本文标题:11-7&&11-8 C++

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