I want to test what delete in c++ can do so wrote the following:
#include <iostream>
#include <vector>
using namespace std;
class A{
public:
  A(string s):a(s){}
  string getS(){
    return a;
  }
private:
  string a;
};
class B{
public:
  B(string str):s(str){}
  void setV(A a){
    v.push_back(a);
  }
  string getS(){
    return s;
  }
private:
  vector<A> v;
  string s;
};
int main(){
  A a("abc");
  B* b = new B("cba");
  b->setV(a);
  cout<<b->getS()<<endl;
  cout<<a.getS()<<endl;
  delete b;
  cout<<b->getS()<<endl;
  cout<<a.getS()<<endl;
  return 0;
}
And I still got the following output:
cba
abc
cba 
abc
looks like I can still get access the memory for both a and b? So my question would be 1.Why do I have access to b, since I have called delete on it? 2.Why do I have access to a, since b's destructor is called so the memory of vector containing a should be free?
Cheers
 
     
    