自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(10)
  • 收藏
  • 关注

原创 Effective C++:绝不重新定义继承而来的缺省参数值

考虑下面这段程序:#include using namespace std;class Shape {public: enum ShapeColor { Red, Green, Blue }; virtual void draw(ShapeColor color = Red) const = 0;};class Rectangle : public Shape {

2016-07-16 16:20:51 518

原创 C++私有继承

概述除了在类中直接声明成员变量外,C++还有另一种实现has-a关系的途径——私有继承。使用私有继承,基类的公有成员和保护成员都将成为派生类的私有成员。这意味着基类方法将不会成为派生类对象公有接口的一部分,但可以在派生类的成员函数中使用它们。下面是私有继承的一个示例:#include #include #include #include using namespace std;

2016-07-15 00:25:02 463

原创 Boost之字符串

lexical_constlexical_const库进行“字面值”的转换,类似C中的atoi函数,可以进行字符串与整数、浮点数之间的字面转换,使用时需要包含头文件。#include #include #include using namespace std;using namespace boost;int main(){ /* 基本用法 */ int x

2016-07-04 16:35:47 499

原创 C++虚函数

下面是一段关于虚函数的程序:#include using namespace std;class Base {public: void funA() { cout << "in Base::funA\n"; } void funB() { cout << "in Base::funB\n"; } v

2016-07-01 20:24:28 285

原创 Boost之智能指针

boost.smart_ptr库提供了六种智能指针,包括scoped_ptr、scoped_array、shared_ptr、shared_array、weak_ptr和intrusive_ptr。为了使用smart_ptr组件,需要包含头文件。Scoped_ptrscoped_ptr是一个很类似auto_ptr/unique_ptr的智能指针,但scoped_ptr的所有权更加严格,不能

2016-06-29 23:26:40 496

原创 C++11之智能指针

概述C++98提供了了智能指针auto_ptr,但C++11已将其摒弃,并提供了unique_ptr和shared_ptr。这三种智能指针模板都定义了类似指针的对象,可以将new获得的地址赋给这种对象。当智能指针过期时,这些内存将自动被释放。其基本用法如下:#include #include #include class Report{private: std::str

2016-06-25 16:07:14 329

原创 Boost之日期时间处理(date_time库)

概述使用date_time库需要在编译时加上"-lboost_date_time",而且需要包含以下头文件:处理日期的组件:#include 处理时间的组件:#include date类date是date_time库处理日期的核心类,使用一个32位的整数作为内部存储,以天为单位表示时间点概念。date也全面支持比较操作和输入输入出,我们可以完全把它当成一个像int、st

2016-06-24 22:04:20 10874

原创 Boost之时间处理(timer库)

一. timerimer是一个小型的计时器,提供毫秒级别的计时精度和操作函数#include #include using namespace std;using namespace boost;int main(){ timer t; cout << "max timespan:" << t.elapsed_max() /3600 << "h" <<en

2016-06-20 19:27:57 606

原创 排序算法(C++实现)

#include using namespace std;template void Swap(T & left, T & right) { T temp = left; left = right; right = temp;}/* 简单选择排序 */template void SelectSort(T * arr, int n) { for (i

2016-05-06 23:41:00 2561

原创 QString与其它类型的转换

1. QString与int、double等类型的转换QString转int、double:QString intStr = "10";int intNum = intStr.toInt();QString doubleStr = "11.11";double doubleNum = doubleStr.toDouble();int、double转QString:int intNum = 10

2015-09-14 01:15:32 374

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除