[ create a new paste ] login | about

Link: http://codepad.org/kTv0QrIM    [ raw code | output | fork ]

C++, pasted on May 8:
#include <iomanip>
#include <iostream>
using namespace std;

template< class T >
class cPtr{
    T * ptr;
public:
    cPtr(T *p = 0){
        ptr = p;
    }
    T * operator()(void) const{
        return ptr;
    }
    ~cPtr(){
        delete ptr;
    }
};

int main(){
    int * val1 = new int[1];
    int * val2 = new int[1];
    (*val1) = 256;
    (*val2) = 128;
    cPtr< int > p1(val1);
    cPtr< int > p2(val2);
    cout<<hex<<p1()<<endl;
    cout<<hex<<p2()<<endl;
    p1 = p2;
    p2 = p1;
    cout<<hex<<p1()<<endl;
    cout<<hex<<p2()<<endl;
    return 0;
}


Output:
1
2
3
4
5
6
7
0x8085438
0x8085460
0x8085460
0x8085460
block freed twice

Exited: ExitFailure 127


Create a new paste based on this one


Comments: