C++

C++中两个类相互引用的情况

Question 现在有两个类A和B需要定义,定义A的时候需要用到B,定义B

C++ vector push_back() Vs emplace_back

Introduce std::vector::push_back() Appends the given element value to the end of the container. The new element is initialized as a copy of value. value is moved into the new element. If the new size() is greater than capacity() then all iterators and references (including the past-the-end iterator) are invalidated. Otherwise only the past-the-end iterator is invalidated. (Cite from: cppreference.com)

Translation of Programming Languages(CU CPSC8270)

编译原理这门课程是我在CU的2018 Fall选修的一门专业核心课程,老师是Clemson CS系比较受欢迎的 Brian Malloy教授。在他的个人主页上面也有Python, C++, 2D游戏的教程,非常适合对CS感兴趣的同学学习。

C++软件设计模式之Singleton

什么是Singleton? 单例模式(Singleton),保证一个类仅有一个实例,并提供一个访问它的全局访问点。 可以考虑在下面的一些场景中应用: Windows的Task Manager(任务管理器)就是很典型的单例模式(这个很熟悉吧),想想看,是不是呢,你能打开两个windows task manager吗? 不信你自己试试看哦~  windows的Recycle Bin(回收站)也是典型的单例应用。在整个系统运行过程中,回收站一直维护着仅有的一个实例。 网站的计数器,一般也是采用单例模式实现,否则难以同步。 应用程序的日志应用,一般都何用单例模式实现,这一般是由于共享的日志文件一直处于打开状态,因为只能有一个实例去操作,否则内容不好追加。 Web应用的配置对象的读取,一般也应用单例模式,这个是由于配置文件是共享的资源。 在数据库连接池的设计一般也是采用单例模式,因为数据库连接是一种数据库资源。数据库软件系统中使用数据库连接池,主要是节省打开或者关闭数据库连接所引起的效率损耗,这种效率上的损耗还是非常昂贵的,因为何用单例模式来维护,就可以大大降低这种损耗。 多线程的线程池的设计一般也是采用单例模式,这是由于线程池要方便对池中的线程进行控制。 操作系统的文件系统,也是大的单例模式实现的具体例子,一个操作系统只能有一个文件系统 上述内容来自于: 单例模式的常见应用场景 单例模式应用的场景一般发现在以下条件下: 资源共享的情况下,避免由于资源操作时导致的性能或损耗等。如上述中的日志文件,应用配置 控制资源的情况下,方便资源之间的互相通信。如线程池等。

C++ Static关键字的用法说明

C++中Static关键字的应用 由于C++是一种源自于C的语

C++ 变量的初始化问题

介绍 在C++语言中int a;表示声明了整型a但未初始化,而C

C++声明与定义的区别

Introduce 声明 声明一个变量只是将变量名标识符的有关信息告诉编译器,使

C++之Rule of Five

Rule of five Because the presence of a user-defined destructor, copy-constructor, or copy-assignment operator prevents implicit definition of the move constructor and the move assignment operator, any class for which

C++之Rule of Zero

Classes that have custom destructors, copy/move constructors or copy/move assignment operators should deal exclusively with ownership (which follows from the Single Responsibility Principle). Other classes should not have custom destructors,