A
Alexander Pandit
hi ,
I've been reading following article :
http://www.artima.com/cppsource/bigtwo.html and tried the
first example with my dev-c++ .
When running following code , there should be a runtime error like stated in
the article, because
I'm trying to delete an already deleted pointer. But there is no error in
the output.
Here is my code :
#include <iostream>
#include <stdlib.h>
using namespace std;
class SomeResource {
};
class Example {
SomeResource* p_;
public:
Example() : p_(new SomeResource()) {
std::cout << "Creating Example, allocating SomeResource!\r\n";
}
~Example() {
std::cout << "Deleting Example, freeing SomeResource!\r\n";
delete p_;
}
};
int main(int argc, char *argv[]) {
char c;
{
Example e1;
Example e2(e1);
}
cin >> c;
return 0;
}
Why doesn't an error message show up ? Could it be an compiler option ?
regards, alex
I've been reading following article :
http://www.artima.com/cppsource/bigtwo.html and tried the
first example with my dev-c++ .
When running following code , there should be a runtime error like stated in
the article, because
I'm trying to delete an already deleted pointer. But there is no error in
the output.
Here is my code :
#include <iostream>
#include <stdlib.h>
using namespace std;
class SomeResource {
};
class Example {
SomeResource* p_;
public:
Example() : p_(new SomeResource()) {
std::cout << "Creating Example, allocating SomeResource!\r\n";
}
~Example() {
std::cout << "Deleting Example, freeing SomeResource!\r\n";
delete p_;
}
};
int main(int argc, char *argv[]) {
char c;
{
Example e1;
Example e2(e1);
}
cin >> c;
return 0;
}
Why doesn't an error message show up ? Could it be an compiler option ?
regards, alex