Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function Overloading for the standard library functions in C++

I have a free function as part of a class. In the constructor for the class i am doing some malloc operations . So in the destructor i am trying to free that memory. But VS10 compiler complains that the

free(pointer); 

doesn't match the signature of the free function of my class.

So question is In a class wherein if we have implemented methods which have same names as that of standard library functions . How to call one over the other.

Regards,

like image 226
Jay D Avatar asked Oct 28 '25 22:10

Jay D


1 Answers

You have to use the scope operator to get the correct scope of the free function:

::free(pointer);

Having :: at the beginning tells the compiler to look for the free function at the global scope, not the closest scope which is your class.

like image 159
Some programmer dude Avatar answered Oct 30 '25 13:10

Some programmer dude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!