C++
JackReach
搬砖啊
展开
-
c++圆练习题
0x00 面向对象概述引用"c++编程思想"的神句:万物皆是对象。抽象对象,看起来就挺抽象的,怎么让人理解啥是抽象对象呢?其实通俗来讲就是将现实生活存在的,描述成计算机可以理解的代码,所以就有了抽象对象这个名词。0x01 代码编写int main(){ //创建circular对象 circular* myCircular = new circular(); if (N原创 2017-09-13 10:39:03 · 530 阅读 · 0 评论 -
cpp函数传递值的三种方式
0x00 函数传递值的三种方式值传递、地址传递、引用传递 0x01 代码/* 通过解析mysql 的查询函数,来理解函数传递方式const char *query 地址传递unsigned long length*/int mysql_real_query(MYSQL *mysql, const char *query, unsigned long length)原创 2017-12-08 08:50:40 · 1532 阅读 · 0 评论 -
cpp引用的运用场景
0x00 引用的运用场景#define OUT //场景1:需要修改实参void TestChangeValue(OUT int& iNum){ iNum = 2;} //场景2:不需要改变实参void TestNoChangeValue(const int& iNum){ //iNum = 3; 报错 //只能用作参数进行加工数据,不能修改传进来的实参 int原创 2017-12-08 01:05:26 · 165 阅读 · 0 评论 -
cpp中类和struct的区别
0x00 代码struct tagDog{ std::string name; void ShowName() { cout name << endl; }};class Dog{ std::string name; void ShowName() { cout name << endl; }}; int main(){ tagDog dd;原创 2017-12-08 00:27:13 · 1544 阅读 · 0 评论 -
cpp全局变量和局部变量的使用
0x00代码int iValue = 100;int main(){ int iValue = 200; //就近原则,输出200的值 cout << iValue << endl; //输出全局参数使用::标记符 cout << ::iValue << endl; return 0;}0x01解析a.有一个问题就是两个变量名重复,这是一个不好的习惯,这里只原创 2017-12-07 23:56:46 · 842 阅读 · 0 评论 -
c++练习-类对象对比大小
0x00 用到的知识点类的封装、有參构造函数、引用、 this指针0x01 代码class Number{public: Number(){}public: Number(const int& iValue) { this->m_Value = iValue; }public: /*两个数相比较大小 const Number& obj 比较数实原创 2017-12-08 18:27:29 · 1975 阅读 · 0 评论 -
c++函数重载的条件
0x00 函数重载的条件 函数重载的四个条件:函数名相同,形参数量不同,形参类型不一样,形参顺序不一样0x01 代码实现int ShowValue(int iValue){ cout << iValue << endl;}//函数名相同、形参个数不同int ShowValue(int iValue, int iValueA){ cout << iValue原创 2017-12-08 17:42:18 · 9152 阅读 · 0 评论 -
函数形参默认值
/*函数设置默认参数 IPAddress 数据库地址 port 端口号,默认3306*/bool ConnectDB(const std::string& IPAddress, int port = 3306){ if ( IPAddress.empty()|| (port < 0)) { return false; } //TODO: connect mysql ser原创 2017-12-08 12:01:33 · 505 阅读 · 0 评论 -
c++练习-构造学生类
#define IN#define OUTclass student{public: student() { }public: student(IN const std::string& strName, IN const int& iAge) { if ( (strName.empty())|| (iAge < 0)) { //用 log 记录错误原创 2017-12-08 11:29:53 · 644 阅读 · 0 评论 -
C++不可继承类final
0x00触发场景经理丢了一份win服务器代码给我,看到一个类这样的写法class xxxx final ,懵了。默默记下来,回来查资料做实验,看一下到底是什么新姿势。0x01测试代码class System final{private: unsigned int version;};//这里winSystem继承System报错class WinSy原创 2017-10-13 07:14:46 · 1844 阅读 · 0 评论 -
检测本身机器大小端
#include #include #include int main(){ unsigned int value = 0x12345678; unsigned char* np = (unsigned char*)&value; printf("%0x-%0x-%0x-%0x \n", np[0], np[1], np[2], np[3] ); r原创 2017-09-01 21:21:16 · 146 阅读 · 0 评论 -
C++自定义命名空间编写
记录一下自定义命名空间的写法0x00 代码实现1、定义命名空间namespace ReacherNameSpace{ //int count_value = 10; //extern int count_value = 10; //不能在命名空间内对定义的变量进行赋值操作 extern int count_value; void ShowMsg();}2、原创 2017-08-29 15:04:43 · 4590 阅读 · 0 评论 -
面向对象三大特性
0x00 唠唠叨叨只是做一个概念的记录0x01 面向对象的三大特性n 封装把客观事物封装成抽象的类,并且类可以把自己的数据和方法只让可信的类或者对象操作,对不可信的进行信息隐藏。类将成员变量和成员函数封装在类的内部,根据需要设置访问权限,通过成员函数管理内部状态。n 继承继承所表达的是类之间相关的关系,这种关系使得对象可以继承另外一类对象的特征和能力。继承的原创 2017-09-13 19:36:37 · 172 阅读 · 0 评论 -
new和delete解析
0x00 new 和 delete 源码void *__CRTDECL operator new(size_t size) _THROW1(_STD bad_alloc) { void *p; while ((p = malloc(size)) == 0) if (_callnewh(size) == 0) { // report no memory原创 2017-09-13 19:21:18 · 274 阅读 · 0 评论 -
C++ Primer 第五版第一章Sales_item.h源码
#ifndef SALESITEM_H // we're here only if SALESITEM_H has not yet been defined #define SALESITEM_H // Definition of Sales_item class and related functions goes here #include #include原创 2018-01-15 09:50:55 · 1946 阅读 · 0 评论