[ create a new paste ] login | about

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

C++, pasted on Jun 7:
#include <iostream>
using namespace std;

class test
{
private :
	char * ptr;
public  :
	  test();
	 //~test();
	 bool init();
	 bool init(const char *str);
	 bool show();
	 void rset();
	 char * pointer(){return ptr;};
};

test::test()
{
	ptr = new char[8];
}

/*test::~test()
{
	//
}*/

bool test::init()
{
	bool bInit = ptr != NULL;
	if( bInit )
		strcpy(ptr, "test");
	return bInit;
}

bool test::init(const char * str)
{
	bool bInit = str != NULL;
	if( bInit )
		strcpy(ptr, str);
	return bInit;
}

bool test::show()
{
	bool bShow = ptr != NULL;
	if( bShow )
		cout<<ptr<<endl;
	return bShow;
}

void test::rset()
{
	if( ptr )
		delete [] ptr;
}

int main()
{
	test * x = new test();
	test * y = x;
	x->init("bla bla");
	x->show();
	char * ptr = x->pointer();
	x->~test();
	x->~test();
	delete x;
	x = NULL;
	cout<<ptr<<endl;
	if(!x)
		cout<<"x - empty"<<endl;
	cin.get();
	return 0;
}


Output:
1
2
3
bla bla
bla bla
x - empty


Create a new paste based on this one


Comments: