在以下示例中,note A::operator B()不返回值.
#include <stdio.h>
using namespace std;
struct B
{
int valb;
B(int x = 10) : valb(x) {
printf("\nB::B()...\n");
}
B(const B& rhs) : valb(rhs.valb) {
printf("\nB::B(const B&)...\n");
}
B(B& rhs) : valb(rhs.valb) {
printf("\nB::B(B&)...\n");
}
void f() const {
printf("\nB::f() const... [%d | 0x%x]\n", valb, this);
}
~B() {
printf("\nB::~B()...\n");
}
};
struct A {
static int gv;
int *vala;
A(int *x = &gv) : vala(x) {
printf("\nA::A()...\n");
}
A(const A& rhs) : vala(rhs.vala) {
printf("\nA::A(const …Run Code Online (Sandbox Code Playgroud)