?????????????C++??????????
???????????? ???????[ 2013/3/19 10:28:35 ] ????????
???????C++????
//: HowMany_2.cpp
#include <iostream>
using namespace std;
class HowMany {
static int objectCount;
public:
HowMany() {
++objectCount;
print("HowMany()");
}
~HowMany() {
--objectCount;
print("~HowMany()");
}
HowMany(const HowMany& h) {
++objectCount;
print("HowMany(const HowMany&)");
}
void print(const char ss[]) {
cout << ss << ": ";
cout << "objectCount = " << objectCount << endl;
return ;
}
};
int HowMany::objectCount = 0;
HowMany f(HowMany x) {
x.print("x argument inside f()");
cout << "Return From f()" << endl;
return x; // ?з???? x
}
int main() {
{
HowMany h;
cout << "Entering f()" << endl;
HowMany h2 = f(h);
}
return 0;
} ///:~
???????н????
????Assembly Code??
38: int main() {
39: {
40: HowMany h;
004017FD lea ecx??[h] ; [h] ????? h ???????
00401800 call @ILT+685(HowMany::HowMany) (004012b2) ; ???ù?????
00401805 mov dword ptr [ebp-4]??0
41: cout << "Entering f()" << endl;
0040180C push offset @ILT+200(std::endl) (004010cd)
00401811 push offset string "Entering f()" (0046f090)
00401816 push offset std::cout (0047ce98)
0040181B call @ILT+660(std::operator<<) (00401299) ; ?????????????????
00401820 add esp??8
00401823 mov ecx??eax
00401825 call @ILT+480(std::basic_ostream<char??std::char_traits<char> >::operator<<) (004011e5)
42: HowMany h2 = f(h);
0040182A push ecx
0040182B mov ecx??esp ; ??? ESP ??????????????????Temp???????
0040182D mov dword ptr [ebp-18h]??esp
00401830 lea eax??[h]
00401833 push eax ; ??h???????[h]?????
00401834 call @ILT+0(HowMany::HowMany) (00401005) ; ?????????????????h???????????Temp???????
00401839 mov dword ptr [ebp-1Ch]??eax
0040183C lea ecx??[h2]
0040183F push ecx ; ??h2???????[h2]?????
00401840 call @ILT+640(f) (00401285) ; ????f()????
00401845 add esp??8
00401848 mov dword ptr [ebp-20h]??eax
43: }
0040184B lea ecx??[h2]
0040184E call @ILT+500(HowMany::~HowMany) (004011f9) ; ??????????????????h2
00401853 mov dword ptr [ebp-4]??0FFFFFFFFh
0040185A lea ecx??[h]
0040185D call @ILT+500(HowMany::~HowMany) (004011f9) ; ??????????????????h
44: // getchar();
45: return 0;
00401862 xor eax??eax
46: } ///:~
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11