/*#include "opencv2/opencv.hpp" #include "opencv2/objdetect.hpp" #include "opencv2/highgui.hpp" #include "opencv2/imgproc.hpp" #include "opencv2/test.h" */
#include <iostream> using namespace std; /* *test class override */ class father{ public : int test(){return 1;} virtual int vtest(){return 1;} }; class son:public father{ public: int test(){return 2;} int vtest(){return 2;} }; int test(father &f){ return f.test(); } int test(father *f){ return f->test(); } int vtest(father f,bool s){ return f.vtest(); } int vtest(father &f){ return f.vtest(); } int vtest(father *f){ return f->vtest(); } void test1(){ son a; printf("test class overwrite:%d,%d,%d\n",a.test(),test(a),test(&a)); printf("vtest class override:%d,%d,%d\n",a.vtest(),vtest(a),vtest(&a)); printf("vtest class override:%d\n",vtest(a,true)); } /* * test pointer */ void test2(){ int b[2]={1,2}; int *a=b; cout<<a[1]<<":"<<*(a+1)<<endl; } /* * test int and unsigned int's operator > * 要防止用int负数跟unsigned数进行比较 * 否则int负数就会被当成unsigned数 */ void test3(){ int a=-1; size_t b=1; cout<<"a=-1,b=unsigned 1"<<endl; cout<<"a>(size_t)b ? :"<<(a>b)<<endl<<"a>(int)b ?:"<<(a>(int)b)<<endl; vector<int> s={}; //ERROR: //unsigned 0 -1 = unsigned .... //i<-1 overflow for(int i=0;i<(int)(s.size()-1);i++){ s[i]=0; } for(int i=0;i<(int)s.size()-1;i++){ s[i]=0; } } /* * test stl vector and xxx_bound */ void test4(){ vector<int> s={5,4,3,2,1}; vector<int>::iterator it=lower_bound(s.begin(),s.end(),7,greater<int>()); cout<<"lower bound bigger than 7:"<<*it<<endl; it=lower_bound(s.begin(),s.end(),4,greater<int>()); cout<<"lower bound bigger than 4:"<<*it<<endl; it=upper_bound(s.begin(),s.end(),4,greater<int>()); cout<<"upper bound bigger than 4:"<<*it<<endl; it=lower_bound(s.begin(),s.end(),4,less<int>()); cout<<"lower bound smaller than 4:"<<*it<<endl; } /* *test bit algorithm */ void test5(){ unsigned int a=((unsigned int)(~0))/2; int b=(~0)>>1; printf("%x:%x\n",a,b); int c=1<<2+3; cout<<c<<endl; } /* * test stl map and list */ void test6(){ map<int,int> s; s.erase(2); list<int> l={1,2}; typedef list<int>::iterator It; It it=l.begin();it++;it=++l.begin(); cout<<*it<<endl; //ERROR: l.begin()+n //for list iterator don't support +/- n operation } int main(){ test3(); test4(); test5(); test6(); return 0; }