Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C++Niche Syntax: Function Reference Type Declaration: const reference?

This is a niche question, but I’m struggling to find a sufficient answer. Struct members can be const, but can a function pointer/reference member be declared const? Based off my reading of C++17 section 9.3, I don’t think so…

struct Ex {
  const int i;
  void (*pfn)(int i); // can pfn be a const member?
  void (&rfn)(int i); // can rfn be a const member?
};

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  1. Yes:
    struct Ex {
        const int i;
        void (*const pfn)(int i); // 1. can pfn be a const member?
        void (&rfn)(int i);       // 2. can rfn be a const member?
    };
    
  2. It already is – You can’t assign to a member referencing a function.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading