a matter of semantics


No replies
digitaladdictions
digitaladdictions's picture
Offline
My name if Forest WiBit.Nothing on Earth could stop the coding...A Coding BeautyDriving Ms. ChickyWe propose a toast! To you!W007! I watched 10 vids!
Joined: 2011-12-07
Points: 7210

 

This may have been covered in the C++ videos but if it was at the time it just went over my head as irrelevant at the moment and did not register. If so I am sorry. 

I was examining the example code for the boost asio library for the purpose of network programming. Specifically I was looking at the chat client/server example on this page.

http://www.boost.org/doc/libs/1_48_0/doc/html/boos...

In the chat_message.hpp header they defined a method twice only changing the return type.

 

const char* data() const

{

  return data_;

}

 

char* data()

{

  return data_;

}

 

It took quite a bit of investigation work but I finally figured out that this was because an object of the class with those methods could potentially be instantiated as a const and const objects can only call const methods. Having the data method defined twice allows both const and non-const objects call the data method.  

My question is what is the proper way to refer to this?  Is it overloading? Since the argument lists are identical in this case and only the return type is different I do not know if that is the case. Heck I do not know if using const in the return type even in theory makes it a different return type or not its still the same in memory. Just looking for the proper terminology to communicate with others when you define two copies of a method in this way.