AnswerBun.com

How to use the "clockwise/spiral rule" to read a const class member function?

Stack Overflow Asked by IvanaGyro on December 13, 2020

How to use the "clockwise/spiral rule" to read a const class member function? Like:

class Box {
    // ...
    double volume() const;  // <= How to read this function?
}

One Answer

It's not quite the spiral rule here, as that isn't a singular type definition, but a function instead:

 double volume() const;
  ^       ^       ^---- Operates on const instance of Box
  |       --- Function name
  -- Return type

Anything with a trailing const on it can operate on const Box, while absent that, you need a mutable version or you can't use it. You'll get some kind of compiler error saying it can't find a function for a const Box even though you'd suppose such a function is defined.

Often you'll see things like:

  const myType& getType() const;

Where that returns a const value from a const instance. These often end up paired, as in:

  const myType& getType() const;
  myType& getType();

Where the first one is for read-only access, and the second one allows alteration.

Correct answer by tadman on December 13, 2020

Add your own answers!

Related Questions

Pass a generic class in method parameter

2  Asked on December 18, 2021 by astha-srivastava

     

Create a pivot table using two columns treating them as a group

2  Asked on December 18, 2021 by chris-reiche

         

PHP get data form XML using PHPSimpleXML

2  Asked on December 18, 2021 by xenpanda

     

docker commands not working with latest version

1  Asked on December 18, 2021 by rod-talingting

     

Space line above sticky top navbar

0  Asked on December 18, 2021 by aurelien

     

PHP for directory as opposed to a file

1  Asked on December 18, 2021 by j-lo

   

Pandas to Json Formatting issue

1  Asked on December 18, 2021 by petereg157

       

react-native-camera orientation change freeze

0  Asked on December 18, 2021 by xtealer

         

KeyError is raised when key exists in dictionary

2  Asked on December 18, 2021 by andrey-kiselev

   

How to insert date and time in Oracle databases?

1  Asked on December 18, 2021 by clancinio

         

How to get one data from database by id (MEAN Stack)?

1  Asked on December 16, 2021 by dorottya-burmeister

         

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP