New course! Every coder should learn Generative AI!
Try a free lesson0
For (1.) you have to override the class default assignment operator. Something like this:
class Class {
public:
Class(){x=0;}
//Assignment
void operator=(int rhs){x=rhs;}
private:
int x;
};
You can then do Class b=5; with the above class.
For (2.) to rethrow the same exception you simply use 'throw' on its own like this:
try{
Class d(7,0);
} catch (...) {
cout << "0 not allowed!"<<endl;
throw;
}