// test_safe2.cc second of sequence, shows SAFE design of a class // test_safe1.cpp does not have // copy constructor, 'explicit' AND operator= // all three are needed to be safe !!! #include using namespace std; int main() { cout << "test_safe2.cc is SAFE" << endl; class safe2 { public: explicit safe2(){i=0; a=0;} // add explicit, make 'i' items in a explicit safe2(safe2 & x) // add explicit and copy constructor {i = x.get(); a = new int[i]; for(int j=0; j=i) throw "BAD index"; *(a+index)=val;} int get(int index){if(index<0 | index>=i) throw "BAD index"; return *(a+index);} safe2 & operator=(safe2 &x){i = x.get(); a = new int[i]; for(int j=0; j