@JackLiuKK
2017-06-11T06:15:51.000000Z
字数 2431
阅读 7426
In other words, your "String" class could be used in the following code and be complied successfully by a standard C++ compiler.
void foo(String x){}void bar(const String& x){}String baz(){String ret("world");return ret;}int main(){String s0;String s1("hello");String s2(s0);String s3 = s1;s2 = s1;foo(s1);bar(s1);foo("temporary");bar("temporary");String s4 = baz();std::vector<String> svec;svec.push_back(s0);svec.push_back(s1);svec.push_back(baz());svec.push_back("good job");}
void main(){char a = 'a';int b = 0;int *pInt1 = &b;int c = *pInt1;pInt1 = (int*)(&a);int *pInt2 = pInt1 + 1;int d = *pInt2;void *pV = &a;pV++;char e = *pV;}
Common.h
int var1;void foo(int input){// some code}
TestA.h
#include "Common.h"#include "TestB.h"class CTestA{private:CTestB m_b;};
TestB.h
#include "Common.h"#include "TestA.h"class CTestB{private:CTestA m_a;}
TestA.cpp
#include "TestA.h"// some code
TestB.cpp
#include "TestB.h"// some code
int foo(std::map<int, int>& mapIn, std::set<int>& setIn){std::vector<int> va(10);std::vector<int> vb;std::copy(va.begin(), va.end(), vb.begin());std::vector<int> vc(100);auto iter = va.begin() + 5;int varInt = *iter;va.push_back(vc.begin(), vc.end());varInt = *(++iter);if (mapIn[4] == 0){// do something}auto itVec = std::find(vc.begin(), vc.end(), 100);if (itVec != vc.end()){// do something}auto itSet = std::find(setIn.begin(), setIn.end(), 10);if (itSet == setIn.end()){// do something}}
TypeA could be either a function pointer or a functor, please try to provide the definition for TypeA in both function pointer way and functor way.
void foo(TypeA processor){int paraInt = 0;const char* pParaStr = "Test";int rtn = processor(paraInt, pParaStr);}