简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!
优质专栏:Audio工程师进阶系列【原创干货持续更新中……】🚀
人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药.
1.前言
本篇目的:理解C++非const转const类型
2.应用实例
v1.0 const int* to int*.
#include <iostream>
using namespace std;
int main(){
const int x = 7;
//v1.0:
//int *p = &x; //error
//v2.0: const int* to int*;
int *p = (int*)&x;
printf("*p = %d\n",*p);
//or
int *y =const_cast<int*>(&x);
printf("*y = %d\n",*y);
//v3.0: const char* to char*.
const char *buf = "abcdefghi";
//char *rev = buf;//error
char *rev = const_cast<char*>(buf);
printf("rev = %s\n",rev);
//v3.0
return 0;
}