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

Update sql database from datagridview in c#

2  Asked on December 25, 2021 by user13987069

   

Wait for observable to get array-data

2  Asked on December 25, 2021 by bena

     

How can you add an object into json through python

1  Asked on December 25, 2021 by jonasmanthebot

   

Pandas reindex to fill date index

1  Asked on December 25, 2021 by niviral

       

checking if file exists in FileInfo[]

1  Asked on December 25, 2021 by abhilash-vg

     

Processing of a file: byte arrays and dimentions

2  Asked on December 25, 2021 by ld420

   

CSS Grid template areas in wrong order

1  Asked on December 25, 2021

   

c++ should I prefer union or exception

2  Asked on December 25, 2021 by chetzacoalt

   

How to set default state for an object when using useState

1  Asked on December 25, 2021 by ross-attrill

   

friend class and the scope of function arguments

2  Asked on December 25, 2021 by user2269707

   

How to remove unchecked value from list?

3  Asked on December 25, 2021 by afelip

   

handling for loop exceptions

6  Asked on December 25, 2021 by sivaram

     

How to filter JSON Data in JS

1  Asked on December 25, 2021 by user12129876

       

Ask a Question

Get help from others!

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