+ Link For Assignments, GDBs & Online Quizzes Solution |
+ Link For Past Papers, Solved MCQs, Short Notes & More |
#include <iostream.h>
class Location
{
int l1;
int l2;
public:
Location();
Location(int lon,int lat);
void view();
Location operator ++();
Location operator --();
void* operator new (size_t size);
void operator delete( void * ptr );
};
Location::Location()
{
l1=0;
l2=0;
}
Location::Location(int lon,int lat)
{
l1=lon;
l2=lat;
}
void Location::view()
{
coutendl"Longitude : "l1endl;
cout"Latitude : "l2endlendl;
}
void* Location::operator new(size_t size)
{
cout"Overloaded new operator called....." endl;
void * rtn = malloc (size ) ;
return rtn;
}
Location Location::operator ++()
{
++l1;
++l2;
}
Location Location::operator --()
{
--l1;
--l2;
}
void Location :: operator delete( void *memory )
{
cout"Overload delete operator called....."endlendl;
free( memory );
}
main()
{
system("cls");
Location l1(10,20), *l2= new Location(30,40);
coutendl"Coordinates for Location 1:";
l1.view();
++l1;
cout"After applying overloaded ++ operator on Location 1 : ";
l1.view();
cout"Coordinates for Location 2:";
l2[0].view();
--l2[0];
cout"After applying overloaded -- operator on Location 2 : ";
l2[0].view();
delete l2;
system("pause");
}
Tags:
+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)
+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)
+ Click Here to Search (Looking For something at vustudents.ning.com?) + Click Here To Join (Our facebook study Group)object k through he hai dear..more clarify me ur point ..
but muzamil yah compail ni ho rhi
there is not wrong with this file ..go to first discussion about this assignment u will get the whole idea..
Brother! what the heck "malloc" is? where you did declare this?
malloc and calloc function for allocating a memory ..in this assignment u havce to overload new operator coz object always can allocate the memory by new operator in dynamically..so u have to defined a malloc or calloc function to allocate memory in the definition of overloading new operator ..okay ?
similarly when we are allocating memory by malloc or calloc functions then its our responsibility to free the memory allocated... so u have to overload delete operator for it..
can u plz tell k press enter to continue likhne k liye kon sa code use hota hai aur kahan pe??
system("PAUSE");
Thanks brther!
thanks a lot
complte and 100% correct
© 2021 Created by + M.Tariq Malik.
Powered by
Promote Us | Report an Issue | Privacy Policy | Terms of Service
We are user-generated contents site. All product, videos, pictures & others contents on site don't seem to be beneath our Copyrights & belong to their respected owners & freely available on public domains. We believe in Our Policy & do according to them. If Any content is offensive in your Copyrights then please email at m.tariqmalik@gmail.com Page with copyright detail & We will happy to remove it immediately.
Management: Admins ::: Moderators
Awards Badges List | Moderators Group
All Members | Featured Members | Top Reputation Members | Angels Members | Intellectual Members | Criteria for Selection
Become a Team Member | Safety Guidelines for New | Site FAQ & Rules | Safety Matters | Online Safety | Rules For Blog Post