forked from zhmzhen/candcppCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcppLamdaNotNew.cpp
55 lines (50 loc) · 1.6 KB
/
cppLamdaNotNew.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <functional>
#include <string>
using FilterFactoryCb = std::function<void(std::string & pStr)>;
class Tclass {
public:
Tclass () {
std::cout << "\t\tCon fun of Tclass is called" << std::endl;
}
//Tclass(const Tclass& pTC) = delete;/*{
Tclass(const Tclass& pTC) {
std::cout << "\t\tCopy Construct Tclass is called" << std::endl;
this->name = pTC.name;
}
~Tclass () {
std::cout << "\t\tDeConstruct fun of ~Tclass is called" << std::endl;
}
void display() const {
std::cout << "\t\tTclass::display,class name: " << name << std::endl;
}
private:
std::string name="Tclass";
};
//FilterFactoryCb returnLamdaFunc(std::string & pStr) {
//https://cloud.tencent.com/developer/article/2322118
auto returnLamdaFunc(std::string & pStr) {
Tclass t;
std::cout << "\treturnLamdaFunc: passed from returnLamdaFunc pStr: " << pStr << std::endl;
//std::reference_wrapper<Tclass> t = t1;
//t = std::cref(t1);
return [t] (std::string& pLstring) -> void {
std::cout << "\tL:Before remove t" << std::endl;
t.display();
std::cout << "\tL:after remove t" << std::endl;
std::cout << "\tL:Passed pLstring: " << pLstring << std::endl;
};
}
int main() {
std::cout << "main: enter" << std::endl;
std::cout << "main: before define aMain " << std::endl;
std::string l_l_str = "assignment";
auto aMain = returnLamdaFunc(l_l_str);
std::cout << "main: after define aMain " << std::endl;
std::string l_amain = "Call aMain";
std::cout << "main: before call aMain " << std::endl;
aMain(l_amain);
std::cout << "main: after call aMain " << std::endl;
std::cout << "main: exit" << std::endl;
return 0;
}