#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
class A
{
public:
A() { printf("A created.\n"); }
~A() { printf("A destroyed.\n"); }
};
class B
{
public:
B() { printf("B created.\n"); }
~B() { printf("B destroyed.\n"); }
};
A g_A;
int foo()
{
printf("\nfoo() ----------------->\n");
A localA;
static B localB;
printf("\nfoo() <-----------------\n");
return 0;
}
int main()
{
printf("main() ------------------>\n");
foo();
foo();
printf("\nmain()<----------------\n");
system("pause");
return 0;
}
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
class A
{
public:
A() { printf("A created.\n"); }
~A() { printf("A destroyed.\n"); }
};
A* createA()
{
A* p = new A();
return p;
}
void deleteA(A* p)
{
delete p;
}
int main()
{
A *pA = createA();
pA = createA();
deleteA(pA);
system("pause");
return 0;
}
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
class A
{
public:
A() { printf("A created.\n"); }
A(A& a) { printf("A created with copy\n"); }
~A() { printf("A destroyed.\n"); }
};
A foo(A a)
{
A b;
return b;
}
int main()
{
A a;
a = foo(a);
system("pause");
return 0;
}
[C++应用程序性能优化]对象的生命周期
最新推荐文章于 2025-04-09 09:44:53 发布