S
saratoga
Hi, all!
I've 'Segmentation fault' in this code. I've found that there are two
calls to destructor.
TestSTL.h:
#include <list>
#include <string>
#include <iostream>
using namespace std;
class TestSTL
{
string *_str;
public:
TestSTL() { _str = new string("test"); };
~TestSTL() { cerr << "destruct" << endl; delete _str; }
};
TestSTL.cpp:
#include "TestSTL.h"
int main()
{
list<TestSTL> lst;
lst.push_back(TestSTL());
}
Could U explain to me what's wrong here?
Thanx.
With the best regards
Daniel.
I've 'Segmentation fault' in this code. I've found that there are two
calls to destructor.
TestSTL.h:
#include <list>
#include <string>
#include <iostream>
using namespace std;
class TestSTL
{
string *_str;
public:
TestSTL() { _str = new string("test"); };
~TestSTL() { cerr << "destruct" << endl; delete _str; }
};
TestSTL.cpp:
#include "TestSTL.h"
int main()
{
list<TestSTL> lst;
lst.push_back(TestSTL());
}
Could U explain to me what's wrong here?
Thanx.
With the best regards
Daniel.