Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class A
- {
- public:
- A(const char *fun_name, int b, int c, int d, int e = 200) :
- fun_name(fun_name),
- b(b),
- c(c),
- d(d),
- e(e)
- {}
- ~A()
- {
- cout << "Destructed (called from " << fun_name << ")\n";
- }
- const char *fun_name;
- int b;
- int c;
- int d;
- int e;
- };
- int fun1(const A *a)
- {
- return a->b + a->c + a->d + a->e;
- }
- int fun2(const A &a)
- {
- return a.b + a.c + a.d + a.e;
- }
- int main()
- {
- // Usando função com ponteiro
- // cout << fun1(&A(3, 6, 9)) << "\n"; // error: taking address of temporary
- A a("fun1", 3, 6, 9);
- cout << fun1(&a) << "\n";
- cout << "fun1 ended\n";
- // Usando função com referência constante
- cout << fun2(A("fun2", 3, 6, 9)) << "\n";
- cout << "fun2 ended\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement