永城房产,上万警民搜捕,老狗友友
3.操作记录的类,记录节点状态,设置节点状态,显示节点状态
=======
代码:
#include <iostream> #include <string> using namespace std; class op { public: double a; double b; virtual double jisuan() { return 0; } }; class add : public op { double jisuan() { return a + b; } }; class sub : public op { double jisuan() { return a - b; } }; class divv : public op { double jisuan() { return a / b; } }; class mul : public op { double jisuan() { return a * b; } }; class fac { public: static op *selectop(char c) { switch (c) { case '+': return new add(); break; case '-': return new sub(); break; case '*': return new mul(); break; case '/': return new divv(); break; default: printf("you entered wrong caculation!!"); break; } } }; int main(void) { op *opr = fac::selectop('/'); opr->a = 100; opr->b = 5; cout << opr->jisuan() << endl; return 0; }
代码:
#include <iostream> #include <string> using namespace std; class op { public: double a, b; virtual double jisuan() { return 0; } }; class add : public op { double jisuan() { return a + b; } }; class sub : public op { double jisuan() { return a - b; } }; class divv : public op { double jisuan() { return a / b; } }; class mul : public op { double jisuan() { return a * b; } }; class ifac { private: /* data */ public: virtual op *selectop() = 0; }; class addop : public ifac { public: static op *selectop() { return new add(); } }; class subop : public ifac { public: static op *selectop() { return new sub(); } }; class divop : public ifac { public: static op *selectop() { return new divv(); } }; class mulop : public ifac { public: static op *selectop() { return new mul(); } }; int main(void) { ifac *opp = mulop::selectop(); opp->a=90; opp->b=100; cout << opp->jisuan()<<endl; return 0; }
public: int a=100; }aa; #include <iostream> #include <string> class { public: int a = 100; } aa; class singleinstance { private: /* data */ int i = 0; public: static singleinstance *instance; singleinstance(int a) { this->i = a; } static singleinstance *get_instance() { return instance; } }; singleinstance *singleinstance::instance = new singleinstance(1995); class b:public singleinstance { }; int main(void) { singleinstance *s1=singleinstance::get_instance(); singleinstance *s2=b::get_instance(); std::cout<<(s1==s2)<<std::endl; std::cin.get(); return 0; }
#include <iostream> #include <string> using namespace std; class girl { public: girl(string); girl(); ~ girl(); string name; private: }; girl:: girl(string s1) { name = s1; } girl::~ girl() { } girl::girl() { name = "不知名的!"; } class gift { public: virtual void gift1() = 0; virtual void gift2() = 0; }; class gg:public gift { public: gg(girl); ~gg(); void gift1() { cout << mm.name << "送你礼物1" << endl; } void gift2() { cout << mm.name << "送你礼物2" << endl; } private: girl mm; }; gg::gg(girl m) { mm = m; } gg::~gg() { } class proxy :public gift { private : gg gg1; public: proxy(girl mm) :gg1(mm) { } void gift1() { gg1.gift1(); } void gift2() { gg1.gift2(); } }; int main(void) { girl mm1("小妹妹"); proxy p1(mm1); p1.gift1(); p1.gift2(); cin.get(); return 0; }
#include <iostream> #include <string> #include <list> using namespace std; class doing { public: void action1() { cout << "lalala 吃饭了" << endl; } void action2() { cout << "是时候运动了!!!!!" << endl; } private: }; class command { public: command(doing * d) { reciver = d; } virtual void do_doing() = 0; protected: doing* reciver; }; class action1_command:public command { public: action1_command(doing* d) :command(d) { } void do_doing() { reciver->action1(); } }; class action2_command :public command { public: action2_command(doing* d) :command(d) { } void do_doing() { reciver->action2(); } }; class waiter { public: void set_action(command* c) { this->command = c; } void do_action() { this->command->do_doing(); } protected: command* command; }; class waiter_n { public: void set_action(command* c) { this->command.push_back(c); } void do_action() { auto n = command.begin(); while (n!=command.end()) { (*n)->do_doing(); n++; } } private: list<command*> command; }; int main(void) { doing* dd = new doing(); command* action_command1 = new action1_command(dd); command* action_command2 = new action2_command(dd); waiter* w = new waiter(); w->set_action(action_command1); w->do_action(); w->set_action(action_command2); w->do_action(); cout << endl; waiter_n* ww = new waiter_n(); ww->set_action(action_command1); ww->set_action(action_command2); ww->do_action(); return 0; }
#include <iostream> #include <string> using namespace std; class request { public: string request_name; string request_type; int n; private: }; class manager { public: manager(string n, string j, int id) { name = n; job = j; classid = id; } void setsuper(manager *p) { this->super = p; } virtual void apply(request*) = 0; int classid; manager* super; string name; string job; private: }; class zhuguan:public manager { public: zhuguan(string n, int id) :manager(n,"主管", id) {} void apply(request* r) { if (r->n > this->classid) { cout << r->request_type << "\t" << r->request_name << "\t 被" << this->job << this->name << "审阅!无权限,将继续向上递交!!" << "classid=" << this->classid << endl; super->apply(r); } else { cout << r->request_type << "\t" << r->request_name << "\t 被"<<this->job<<this->name<<"批准!!!"<<"classid="<<this->classid<< endl; } } private: }; class zongjian :public manager { public: zongjian(string n, int id) :manager(n, "总监", id) {} void apply(request* r) { if (r->n > this->classid) { cout << r->request_type << "\t" << r->request_name << "\t 被" << this->job << this->name << "审阅!无权限,将继续向上递交!!" << "classid=" << this->classid << endl; super->apply(r); } else { cout << r->request_type << "\t" << r->request_name << "\t 被" << this->job << this->name << "批准!!!" << "classid=" << this->classid << endl; } } private: }; class zongjingli :public manager { public: zongjingli(string n) :manager(n, "总经理", 1000) {} void apply(request* r) { cout << r->request_type << "\t" << r->request_name << "\t 被" << this->job << this->name << "批准!!!" << "classid=" << this->classid << endl; } private: }; int main(void) { request* request = new request(); request->request_name = "生病请10天假"; request->request_type = "病假"; request->n = 50; zhuguan* zg = new zhuguan("小芳", 10); zongjian* zj = new zongjian("小明", 30); zongjingli* zjl = new zongjingli("老大"); zg->setsuper(zj); zj->setsuper(zjl); zg->apply(request); return 0; }
#include <iostream> #include <boost/array.hpp> #include <string> using namespace std; int main(void) { boost::array<int,10> arr = { 0,1,2,3,4,5,6,7,8,9 }; boost::array<int, 10>::iterator ib = arr.begin(); boost::array<int, 10>::iterator ie = arr.end(); for (;ib!=ie;ib++) { cout << *ib << endl; } cin.get(); return 0; }
使用:
代码:
#include <iostream> #include <string> #include <functional> #include <list> #include <algorithm> #include "boost/bind.hpp" using namespace std; using namespace boost; class jia:public binary_function<int,int,void> { public: void operator ()( int i, int j) const { cout << i+j << endl; } private: }; int main(void) { list <int> ls1; ls1.push_back(5); ls1.push_back(15); ls1.push_back(125); for_each(ls1.begin(), ls1.end(), bind1st(jia(),10)); cin.get(); return 0; }
#include <iostream> #include <string> #include <functional> #include <list> #include <algorithm> #include "boost/bind.hpp" using namespace std; using namespace boost; class jia:public binary_function<int,int,void> { public: void operator ()( int i, int j) const { cout << i+j << endl; } private: }; void add(int i, int j) { cout << i + j << endl; } int main(void) { list <int> ls1; ls1.push_back(5); ls1.push_back(15); ls1.push_back(125); //std 方式 for_each(ls1.begin(), ls1.end(), bind1st(jia(),10)); //boost 方式 for_each(ls1.begin(), ls1.end(), bind(add,13, _1)); cin.get(); return 0; }
这个从新做一个文章吧,在这里放不下。。。
#include <iostream> using namespace std; class a { public: void virtual a() { std::cout << "a --> a" << endl; } void virtual b() { std::cout << "a--> b" << endl; } void virtual c() { std::cout << "a--> c" << endl; } private: }; class b :public a { public: void virtual a() { std::cout << "b--> a" << endl; } void virtual b() { std::cout << "b--> b" << endl; } }; typedef void (*pfunc) (void); int main(void) { b b; cout << "b is " <<sizeof(b) << endl; pfunc pfc; for (int i = 0; i < 3; i++) { /* (&b) 取出b的地址 (int *)(&b) 转换b的地址为int 类型,方便后期访问紧跟着它的内存 *(int *)(&b) 取出b里面的内容(虚函数表的地址) (int *) *(int *)(&b) 把虚函数表的地址转换为int类型,方便后期访问紧跟着它的内存 (int *) *(int *)(&b) + i 利用地址存储的机制,+1 自动跳过4(8)个字节,访问下一个内存内容,访问存储在虚函数表里面的函数地址 (pfunc)* 将虚函数表李的函数指针地址转换为 pfunc 类型的函数指针地址,方便调用 pfc(); 调用 */ pfc = (pfunc)*((int *) *(int *)(&b) + i); pfc(); } cin.get(); return 0; }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
如何在没有core文件的情况下用dmesg+addr2line定位段错误
用QT制作3D点云显示器——QtDataVisualization
网友评论