
C++ 基本语法
文章平均质量分 85
沉默的小明兄
世界函数
展开
-
C++ 基本语法
对比 C 语言 ,C++做的一些语法定义。新增了 sting 类型 (注意 string 是一个类)。构造函数:新增 构造函数 和 析构函数 还有初始化参数列表。对象被销毁的时候 调用 析构函数。复制构造函数 ---------> 容易出现操作非法内存,容易出现 段错误。Stu(Stu & stu){// this 是一个对象 stu能取...原创 2016-07-30 11:58:13 · 1201 阅读 · 0 评论 -
c++ 11 智能指针
智能指针编译gcc -std=c++11 test.cpp -o test测试代码#include <iostream>#include <memory>// 编译 加上 -std=c++11int main(){ int a = 10; std::shared_ptr<int> ptr = std::make_shared...原创 2019-08-24 23:46:25 · 168 阅读 · 0 评论 -
C++ std::tuple 和 type_traits 使用
C++ 元组C++ std::tuple 与 python tuple 类似,可以存放不同类型的数据。常用操作// 模板 定义 tuplestd::tuple<int,int,std::string> t(1,2,"hello");//tuple 大小int size = std::tuple_size<decltype(t)>::value;//访问i...原创 2019-09-26 20:47:16 · 310 阅读 · 0 评论 -
c++ 模板template 使用
C++ 模板C++ 模板使用有点类似于Java中的泛型。普通函数模板类模板类成员函数为模板函数测试例子#include <iostream>#include <type_traits>#include <string>// 测试Terminal VT100 颜色打印效果// 一般Terminal都支持256颜色void print...原创 2019-09-26 20:58:26 · 163 阅读 · 0 评论