
C++面试
二月二十月色真美
这个作者很懒,什么都没留下…
展开
-
C++ 类相关知识
运算符重载 常见重载运算符及返回值 常见的重载运算符有: class Time { public: Time operator+(const Time& t) const; //加减乘除返回类型为 Time Time& operator=(const Time& t); //赋值运算符返回类型为 Time&,要注意判断 &t==this Time& operator++(); ...原创 2021-07-08 09:36:00 · 186 阅读 · 0 评论 -
C++11
枚举变量 作用域内枚举 为了避免不同枚举定义中的枚举量的冲突,C++11采用如下解决方法: enum class IEnum1 { one, two, three }; enum class IEnum2 { one, one2, two }; 也可以使用struct代替上述代码中的class。同时需要使用枚举名来限定枚举量,使用如下: IEnum1 myNum = IEnum1::two; 作用域内枚举的类型转换 常规枚举会自动进行类型转换,但作用域内枚举需要显式的进行类型转换,如下:原创 2021-07-07 14:32:45 · 221 阅读 · 0 评论 -
C++基础知识
const 类成员 const int a; 在构造函数中初始化化,可以使用初始化列表初始化 普通变量 const 引用 const int & ra = a; 对变量a的常引用。 const 指针 const char* p = "aaa"; //表示指针指向的元素值不可变 char* const rp = p; //表示指针本身不可变 类函数 int fun() const ; const A a; 对象a只能调用常成员函数。 特殊知识 临时变量都默认为 ...原创 2021-07-02 10:01:16 · 270 阅读 · 0 评论