@JackLiuKK
2017-06-11T16:58:45.000000Z
字数 2873
阅读 5480
void foo(short startIndex){short buffer[50000] = { 0 };for (auto i = startIndex; i < 40000; ++i){buffer[i] = (char)i;}
class CBase{public:CBase(): m_pVar1(NULL){m_pVar2 = new int(4);}~CBase(){delete m_pVar2;delete m_pVar1;}void Init(int* pVar){m_pVar1 = pVar;}private:int* m_pVar1;int* m_pVar2;}class CDerive : public CBase{public:CDerive(int var) : m_var(var) {};~CDerive() {};private:int m_var;}int main(){CDerive* pDerives = new CDerive[10];int *pVar = new int(10);for (int i = 0; i < 10; ++i){pDerive[i].Init(pVar);}delete pDerives;delete pVar;}
class CFoo{public:CFoo() : m_var(0) {};~CFoo() {};bool AddAndCheck() const{m_var += 5;return m_var < 10;}private:int m_var;}
#define INCREASE(a) ++avoid foo(){int a = 3;int b = 7;cout<<INCREASE(a * b)<<endl;}
char* GetStaticBuffer(){char buffer[100] = { 0 };return buffer;}
const int TEN_MEGA_BYTES = 10 * 1024 * 1024;void fooA(){char *pBuffer = new char[TEN_MEGA_BYTES];}void fooB(){char buffer[TEN_MEGA_BYTES] = { 0 };}
class CStudent{public:CStudent() {};~CStudent() {};}class CTeacher{public:CTeacher(CStudent student) {};CTeacher(CStudent student): m_student(student){}~CTeacher() {};void Teach() {};private:CStudent m_student;}void foo(CTeacher teacher){teacher.Teach();}int main(){CStudent student;CTeacher student_teacher;foo(student);}
int fooVar = 10;void foo(int *pVar, int& var){pVar = &fooVar;var = fooVar;}int main(){int var1 = 1;int var2 = 2;foo(&var1, var2);cout<<var1<<":"<<var2<<endl;}
std::vector::resize() and std::vector::reserve()
std::vector::size() and std::vector::capacity()
Hints: Two template parameters. One is a number to be compared as base, another is the element to be compared.