Meaning of const as prefix and suffix of function

Question:
What is the purpose of placing a const at the beginning and end of a function declaration with a de-reference to the function? Are there memory leak implications?

For example:

 const DateTime &dataTime() const
where:
 DateTime is the type of the function        dataTime is the function name

Answer:
Consider:

int const i = 10; 
This declares i to have a type-constant integer, which means that the value of i cannot be modified once it has beeninitialized. Note that this is the same as saying:
const int i = 10;
The rule for this is: const modifies type of what is written before it, except when it is the first word in a declaration, in which case it always modifies the type declarator after it.

So, for uniformity, I like to write the former way.

When the const modifier is applied to a member function, the member function shall not change the state ofthe object it called for. For example:

class Foo {public:   int bar () const;private:   int i;};int Foo::bar () const{   i = 10; // not allowed; const method cannot change state.}

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may