![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++ 之路
文章平均质量分 87
user_define_race
这个作者很懒,什么都没留下…
展开
-
c++ 34 虚函数与多态一
其中,虚函数 动态多态,其他静态原创 2014-11-24 21:47:43 · 373 阅读 · 0 评论 -
c++ 42面向对象表达式Scanner 实现
Scanner 类图。Scanner 作用是,一个字符一个字符的扫描表达式。登记表达式当前的状态。完毕,错误,数字,加法,减法,惩罚,除法,左括号,右括号,变量。Scanner :字符串,数字,当前位置,状态。字符串转成double 的实现为什么是指针的指针?指针传递本质上也是值传递。希望改变指针本身的地址,而不是指针指向的内容。就需要用到指针的指针。看原创 2014-12-06 19:18:41 · 1127 阅读 · 0 评论 -
c++ 41 分清值语义与对象语义
默认的构造拷贝函数是浅拷贝A a1;A a2(a1); //a1 与a2 之间还存在资源的共享一个类实现了深拷贝之后才算是值语义string a("abc");string b(a); //这里是深拷贝对象语义对象生命不容易控制,(容易产生资源泄漏,内存泄漏问题)基于对象编程 值语义值语义对象通常以类对象的方式来使用。面向对象编程 对象语义对象语原创 2014-12-03 21:39:48 · 543 阅读 · 0 评论 -
43 c++ 面向对象版表达式计算器Parser
基本代码完善: 递归实现表达式树: main.cpp #include #include #include "Scanner.h"#include "Parser.h"using namespace std;int main(void){ STATUS status=STATUS_OK; do { cout "; string buf; getli原创 2014-12-07 20:29:35 · 827 阅读 · 0 评论 -
44 c++ m面向对象版表达式计算器 设计缺陷
8-2+1 实际上等于7 ,运行是5,右结合的当前是表达式=项+- 一个表达式 这里8 是一个项,- 后面是一个表达式。所以右结合了。这样设计之后,很多类都没有用了。优化后:Node.h#ifndef _NODE_H_#define _NODE_H_#include #include using namespace std;c原创 2014-12-08 21:11:43 · 675 阅读 · 0 评论 -
链表
#include #include #include struct AdvTeacher{ char name[64]; int age; struct AdvTeacher *next;};//静态链表void main(){ struct AdvTeacher t1,t2,t3; struct AdvTeacher *p=NULL; t1.age=10; t2.a原创 2015-03-16 15:40:23 · 336 阅读 · 0 评论 -
c++40 面向对象的计算器 一
node.h#ifndef _NODE_H_#define _NODE_H_class Node{public: virtual double Calc() const=0;//纯虚函数 virtual ~Node(){};};class NumberNode:public Node{public: double Calc() const; NumberNode(dou原创 2014-11-29 13:37:04 · 827 阅读 · 0 评论 -
c++ 继承 33 虚继承对c++ 对象内存模型造成的影响
#include using namespace std;class BB{public: int bb_;};class B1:virtual public BB{public: int b_;};class B2:virtual public BB{public: int b2_;};class DD:public B1,public B2{public:原创 2014-11-23 23:00:00 · 410 阅读 · 0 评论 -
c++ 38 RTTI ,dynamic_cast ,typeid
dynamic_cast 的用法#include #include using namespace std;class Shape{ public: virtual void Draw()=0;//只要有一个虚函数,这个类就是抽象类 而这里去掉virtual 则会调用基类Draw /*void Draw() { cout<<"Shape Draw"<<end原创 2014-11-29 11:58:36 · 359 阅读 · 0 评论 -
c++ 28 map
#include using namespace std;//map 关联式容器,基于key value 存储的 哈希表的变种 内部红黑树// map map; 模版类int main(void){ return 0;}原创 2014-11-22 11:58:14 · 375 阅读 · 0 评论 -
c++ 27——vector
#include #include using namespace std;typedef vector INTVEC;//vector 模版类 看作是一个类int main(void){ INTVEC v; //空的一个向量,里面没有任何元素 详细:构造看文档 v.push_back(1); v.push_back(2); v.push_back(3); unsigned原创 2014-11-21 22:38:18 · 411 阅读 · 0 评论 -
c++ 36 对象动态创建
shape.h#ifndef _SHAPE_H_#define _SHAPE_H_class Shape{public: virtual void Draw()=0; virtual ~Shape(){};};class Circle:public Shape { public: void Draw() ; ~Circle(); }; cla原创 2014-11-27 23:15:38 · 351 阅读 · 0 评论 -
c++ 29 继承一
简单的一个public继承。#include using namespace std; //代码重用 两个方式//组合、将一个类作为另一个类的对象成员 委托//继承class Base{public: int x_;protected: int y_;private: int z_;};//派生类公有继承基类class PublicInherit:public B原创 2014-11-22 16:09:47 · 329 阅读 · 0 评论 -
c++ 30 继承2
#include using namespace std;class Base{public: Base() { cout<<"Base..."<<endl; } ~Base() { cout<<"~Base..."<<endl; } int b_;};class Derived:public Base{public: Derived() {原创 2014-11-23 17:23:37 · 411 阅读 · 0 评论 -
c++ 32 继承 4
简单使用..#include using namespace std;class Bed//床{public: Bed(int weight):weight_(weight) { } void Sleep() { cout<<"Sleep...."<<endl; }; int weight_;};class Sofa//沙发{public: Sof原创 2014-11-23 19:51:20 · 394 阅读 · 0 评论 -
c++ 35虚函数与多态(二)
基类 之指针指向派生类之对象,调用的是派生类的虚函数这就使得我们可以一致的观点看待不同的派生类对象抽象类不能实例化 #include using namespace std;#include class Shape{public: virtual void Draw()=0;//只要有一个虚函数,这个类就是抽象类 而这里去掉virtual 则会调用基原创 2014-11-26 20:54:32 · 313 阅读 · 0 评论 -
c++ 31 继承3
> 派生类对象也是基类对象。这意味着在使用基类的地方也可用派生类来原创 2014-11-23 19:31:28 · 321 阅读 · 0 评论 -
c++ 单利
#include using namespace std;#include class Singleton{public: static Singleton* GetInstance() { if(0==instance_.get()) { //instance_=new auto_ptr(new Singleton); instance_.reset(new Si原创 2015-07-11 12:34:36 · 377 阅读 · 0 评论