函数重载
函数参数个数,类型,顺序不同
实现原理
编译器会修改函数名,带上参数类型
extern C
在C++中想调用C语言方法
// Cpp
#include <iostream>
// 在C++中想调用C语言方法
extern "C" {
#include "test.h"
}
int main()
{
show(); // 在C++中函数可以重载,编译器会把函数名偷偷修改了
std::cout << "Hello World!\n";
}
// .c
#include "test.h"
void show() {
printf("sfs");
}
// .h
#pragma once
#include<stdio.h>
void show();
// .h
#pragma once
// 如果这是一段cpp的代码,那么加入extern "C"{和}处理其中的代码。
#ifdef __cplusplus
extern "C" {
#endif
#include<stdio.h>
void show();
#ifdef __cplusplus
}
#endif // !__cplusplus
C++与C封装的区别
C 中封装,属性与行为分开处理了,且类型转换检测不够
struct class 默认权限不同
构造,拷贝
- 当我们自己写了拷贝构造,系统不会在提供其他构造
- 当我们自己写了有参构造,系统不会提供默认构造,但是会提供默认拷贝
// 普通构造
Person(