a matter of semantics
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.
Forum Rules/Features
Welcome to the WiBit.net forums! Check out our terms and features:
Hot Topic(s)
Annoy your friends
Is this something you think someone else would enjoy? Is it not for you, but do you know someone who is down with this type of content? Well share away:
Tweet
The Blog
Don't Let XML Make You a Cheater
This blog is a reminder that cheating in software development can get you into big trouble. Sometimes developers get really really lazy, OR are pressured to write something using overly simplified data structures. Almost every time this happens you are bitten in the butt! Sometimes the problems show up immediately and other times it may take months or years (especially in integrated systems).
- 1 of 78
- ››













