I am having a question related to const keyword. I want to know which is the correct way to use it. I have seen both these implementations while I was trying to read about singleton patterns - const Singleton & and Singleton const &. Here is one such example
Thanks @Little Bobby Tables. I have a follow on question. Does pointer precedence rule in stack overflow link apply to references also. In other words, const Singleton& and Singleton const& are not the same
Remember, read it right to left: const Singleton& is a reference to a Singleton (const). Singleton const& is a reference to a const Singleton. Singleton& const is a constant reference to a Singleton.
Note the last one is considered illegal - references are constant anyway, you can't change what they refer to, so there is no point to having a constant reference.