The Java Object has some methods like toString, hashCode, equals, etc. Does an object in C++ have some builtin methods? What are the actual differences between an object in C++ and Java?
Things work differently in Java and C++.
In Java every object inherit from the class Object. This is a base class providing some basic member function like ToString() that can be overridden by subclasses.
In C++ there is no such class like Object. In fact the word object in C++ refers to any type, including non class type.
The new C++11 standard provides a standard function std::to_string that is valid for any object assuming it exists a valid overload.
std::to_string: http://en.cppreference.com/w/cpp/string/basic_string/to_string
std::hash: http://en.cppreference.com/w/cpp/utility/hash
Also equality between any type can be defined through operator==
This exhibits a different choice of design between the two languages. While Java is more object oriented ( base classes provide functionality) the C++ standard library uses the generic programming paradigm (algorithms that can be applied to various types).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With