![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
Wood mood
悬崖十年面壁图破壁
展开
-
C++ class 初学(4)
技巧知识点类是用户定义的类型,对象是类的实例1.有时候,使符号常量的作用域为类很有用,例如,类声明可能使用字面值30来指定数组的长度,但类中的数据成员只描述对象的形式,并没有创建对象a. 可以在类中声明一个枚举,使一个常量作用于类的作用域,class tom{private: enum {months = 12}; double mon [months];};传统的枚举方法中,两个枚举定义中的枚举量可能发生冲突例如:enum egg {small,medium,big};enum原创 2020-12-28 17:38:04 · 149 阅读 · 0 评论 -
C++ class 初学(3)
Destructor naming 析构函数Like constructors, destructors have specific naming rules:The destructor must have the same name as the class, preceded by a tilde (~).The destructor can not take arguments.The destructor has no return type析构函数将类中的说用到的资源,动态分配空间,原创 2020-12-24 11:04:26 · 108 阅读 · 0 评论 -
C++ class 初学(2)
成员函数访问和封装object-oriented programming 面向对象的编程要求我们需要对一些函数进行封装,并将成员变量权限设置为私有,是为了利用黑箱原理,the separation of interface and implementation is extremely useful because it allows us to use objects without understanding how they work. This vastly reduces the complex原创 2020-12-23 08:19:56 · 185 阅读 · 0 评论 -
C++ class 初学(1)
类 class 和结构体 struct的区别A class defaults its members to private. A struct defaults its members to public.…structs inherit from other classes publicly and classes inherit privately.结构体的成员可以由结构体外的任意函数访问#include <iostream> struct DateStruct{原创 2020-12-22 08:24:29 · 229 阅读 · 0 评论 -
C++编程易错和错误检查
1.输入错误If the user has entered invalid input, ask the user to enter the input again.#include <iostream>#include <limits>#include <string> int main(){ std::string hello{ "Hello, world!" }; int index; do { st原创 2020-12-21 09:07:53 · 810 阅读 · 1 评论