C++重学 函数重载,extern C,构造拷贝,explicit,new delete

函数重载

函数参数个数,类型,顺序不同
实现原理
编译器会修改函数名,带上参数类型

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 默认权限不同

构造,拷贝

  1. 当我们自己写了拷贝构造,系统不会在提供其他构造
  2. 当我们自己写了有参构造,系统不会提供默认构造,但是会提供默认拷贝
	// 普通构造
	Person(
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值