C++笔记
liuyi1207164339
这个作者很懒,什么都没留下…
展开
-
C++操作符重载
Matrix.h #pragma once #include "vector" #include "iostream" #define rep(i,n) for(int i=1;i<=n;i++) //宏定义for循环,精简代码 using namespace std; class Matrix { public: //基本构造函数 Matrix(int Row=0, int Column=原创 2015-07-27 11:24:25 · 514 阅读 · 0 评论 -
关于const引用、常量指针、指针常量的一些知识
应该将不需要修改的引用形参定义为const引用。普通的非const引用形参在使用时不太灵活。这样的形参既不能用const对象初始化,也不能用字面值或者产生右值的表达式实参初始化,如下所示: int incr(int &val) { return ++val; } int main() { short v1=0; const int v2=42; int v3=incr(v1); //v1不是一个原创 2015-07-21 22:20:07 · 714 阅读 · 0 评论 -
一道超级坑爹的题目
int a=4; int f(int n) { int t=0; static int a=5; if(n%2) { int a=6; t+=a++; } else { int a=7; t+=a++; } return t+a++; } void main() { int s=a,i=0;原创 2015-08-23 09:43:36 · 1677 阅读 · 2 评论 -
C++中一个计算程序运行时间的工具类
此工具类为单例模式,通过调用其方法能够计算程序的运行时间。 timeHelper.h #include #include class timeHelper { private: clock_t tick_start; clock_t tick_stop; timeHelper(){} //构造函数私有化 static timeHelper *m_pInstance; class原创 2016-04-15 18:09:20 · 1395 阅读 · 0 评论 -
自定义String类:构造函数、复制构造函数、赋值函数的实现
类String的头文件: #pragma once #include class String { public: //普通构造函数 String(const char*str = NULL);//C++ 可以有默认参数 //复制构造函数 String(const String& other); //赋值函数 String& operator=(const String& othe原创 2016-04-21 22:30:55 · 1203 阅读 · 0 评论