How many constructor (including copy constructor) and destructors will be called for test1 and test2?

#include <iostream>
using namespace std;
class Base{
public:
Base(){cout << "Base()" << endl;}
Base(const Base&){cout << "Base(const Base&)" << endl;}
~Base(){cout << "~Base()" << endl;}
};
Base func(Base b){return b;}
void test(){
Base a;
func(a);
}
void test(){
Base a;
Base b = func(a);
}
int main(){
test1();
test2();
return 0;
}

>How many constructor (including copy constructor)
>and destructors will be called for test1 and test2?

Zero. test is redefined and thus the code won't compile. test1 and test2 are neither declared nor defined, thus the code won't compile and certainly won't link.

I think you should name the first function test1() and the second test2(), or else this code won't compile as Narue said...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.