摘要:TiXmlString& TiXmlString::assign(const char* str, size_type len){ size_type cap = capacity(); if (len > cap || cap > 3*(len + 8)) { TiXmlString tmp; tmp.init(len); //这里有new操作 memcpy(tmp.start(), str, len); swap(tmp); } else { memmove(start(), s...
阅读全文
摘要:用struct做map的key会需要"operator #include #include using namespace std;//////////////////////////////////////////////////////////////////////////struct s{ int x; int y;};void main(){ map m; s* a = new s; a->x = 1; a->y = 2; s* b = new s; b->x = 1; b->y = 2; m.insert(pair(a, ...
阅读全文
摘要:#include #include using namespace std;templateclass S{public: S() {} static T* t; static void gen() { static T p; t = &p;/* t = new T();*/ }};class A : public S { public: char carr[1024]; };A* A::t = NULL;class B : public S { public: char carr[2048]; };B* B::t = N...
阅读全文
摘要:#include using namespace std;class A{public: void foo() { func(); } virtual void func() { coutfoo();}运行结果是"b".我就当做是func()为this->func()了.源头是cocos2dx的CCObject的copy()和copyWithZone().
阅读全文
摘要:关于C++的堆空间的NEW和DELETE操作。C的MALLOC等和FREE也是同样的情形。图说明一切。DELETE/FREE之后手动赋值NULL。避免野指针的使用。阿弥陀佛。
阅读全文
摘要:#include <iostream>using namespace std;class elem{public: elem(int n) { i = n; } int i;};template<class T1>class ob{public: ob() {} virtual void foo1(T1* tData) { cout<<"foo1's out"<<endl; }};template<class T2>class obEx : public ob<T2>{public: T2 e;
阅读全文
摘要:#include <iostream>using namespace std;void main(){ int uSize = 0; while(uSize != -1) { //system("cls"); cout<<"in:"; cin>>uSize; cout<<"out:"<<(uSize <= 32 ? uSize <= 16 ? 0 : 1: uSize <= 64 ? 2 : uSize <= 128 ? 3 : -1)<<
阅读全文
摘要:别人问个双色球的事,本人装逼意味随便写写就有了。记过估计弄了1个多点。NM自信心完全受打击。最后还是个丑陋至极的东西。如果不用stl,搜索,随机产生并检测都要自己写。贪图了个安逸结果也没减少时间,CTM啊。开始用set,当然是为了贪图find(),结果不知道出的啥问题,反正肯定就是iterator的问题,烦人的.end()。后来没办法还是用vector,遍历搜索啥的还是没有避免,就为了用erase()来完成避免随机生成的数重复。可选择的多了反而2B了,要是只能用c还不让用STL估计时间也差不多。心情很差。#include <iostream>#include <time.h&
阅读全文
摘要:func(const char*& cp)cp是指向“const char”的指针。cp他是引用。----------------------------------------------------------------------------const char* cpcp是指向“const char”的指针。当然不是说cp必须只能指向const char,他也能指向char类型。但意思是,cp可以修改自己的值从而指向不同地址,但是不能修改指向地址的存储的值。即使是指向char类型的。当你char c = 'a';const char* cp = &c;
阅读全文
摘要:/*如下,函数的形参是引用类型,如果把一个不设定为引用类型的参数传进去,效果入下。基本如预料。*/#include <iostream>using namespace std;void func(int& i){ i = 1;}void main(){ int x = 9; cout<<"before:\t"<<x<<endl; func(x); cout<<"after:\t"<<x<<endl; system("pause");}/*out
阅读全文
摘要:eggache了一下.为了防止自己脑袋秀逗了,试了一下这个。大概这个意思,不过重载运算符没弄,用到字符串类型会有问题。#include <iostream>#include <string>using namespace std;namespace Y4{ template <typename T1, typename T2> class pair { public: T1 first; T2 second; pair() {;} pair(T1 val1, T2 val2) { ...
阅读全文
摘要:1 class A 2 { 3 static ....; //indices and vertices 4 public: 5 void initDataWithD3D(...); //init the graphics with the static data by d3d 6 } 7 8 ......; //initial the static params and reality functions 9 10 11 ........12 ........13 ........14 A* a = new A();15 a->initDataWit...
阅读全文