pickzy.com

C  |  C++  |  Objective-C  |  VC++  |  Win32  |  MFC  |  Java  |  Php  |  Delphi  |  Visual Basic  |  .Net  |  Networking  |  General  |  Games  |  Jobs  |  Javascript  |  




Menu

pickSourcecode.com


        

 




 

Cpp > Programs

 

cpp class pointer

#include <iostream.h>

class myClass

{

public:

myClass(
int val=0):myValue(val) { cout << "In myClass constructor\n"; }
myClass(const myClass & rhs):myValue(rhs.myValue) { cout << "In myClass copy constructor\n"; }

~myClass() { cout << "In myClass Destructor\n"; }

int GetValue() const { return myValue; }
void SetValue(int theVal) { myValue = theVal; }
private:

int myValue;
};




int main()
{

myClass * pc = new myClass(5);

cout << "The value of the object is " << pc->GetValue() << endl;

delete pc;

pc = 0;

cout << "Here is other work, passing pointers around willy nilly.\n Now ready to delete again..." << endl;

delete pc;

cout << "No harm done" << endl;

return 0;

}



 
Privacy Policy | About Us