我有以下C++代码(VS2013):
#include <iostream>
using namespace std;
class A {
int i;
public:
A(int i) : i(i) {
cout << "DEFAULT CTOR " << i << endl;
}
A(const A &o) : i(o.i) {
cout << "COPY CTOR " << i << endl;
}
~A() {
cout << "DTOR " << i << endl;
}
friend A f(const A &, A, A *);
};
A f(const A &a, A b, A *c) {
return *c;
}
int main() {
f(1, A(2), …Run Code Online (Sandbox Code Playgroud) 我有以下C ++代码(VS2013):
#include <iostream>
using namespace std;
class A {
int i;
public:
A(int i) : i(i) {
cout << "Constructor: " << i << endl;
}
A(const A &o) : i(o.i) {
cout << "Copy constructor: " << i << endl;
}
~A() {
cout << "Destructor: " << i << endl;
}
};
A test(const A &a, A b, A *c) {
return *c;
}
int main() {
A b(10);
cout << "START OF TEST" << endl;
test(1, …Run Code Online (Sandbox Code Playgroud)