#include <iostream>
using namespace std;
class B
{
static int count;
int data;
int id;
void print(const char* p)
{
cout <<p <<", "<<id <<", " << data << endl;
}
public:
B(int d=0)
{
data=d; id=++count; print("B(int)");
}
B(const B& a)
{
data=a.data; id=++count; print("B(cost B&)");
}
~B()
{
print("~B()");
}
operator bool()
{
print("bool()"); return (bool)data;
}
B operator+(int i)
{
print("operator+"); return B(data+i);
}
};
int B::count=0;
void main()
{
B b(42);
B x=b+2; // <<<=== HERE IS THE PROBLEM
bool z=b+1;
}
退出超载的&#39; +&#39;功能。 B x = b + 2; //&lt;&lt;&lt; ===这是问题 有什么建议? 感谢