Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

17
  • 3
    Option 2 shouldn't compile in standard C++. Also, nowhere are you passing references to pointers here. Commented Feb 9, 2017 at 23:06
  • 2
    Why do you need to "pass references to pointers in order to use virtual functions"? Commented Feb 9, 2017 at 23:07
  • 1
    In your first example, & is the address-of operator, it has nothing to do with references. Commented Feb 9, 2017 at 23:08
  • 1
    @cafekaze That compiler has some a non-standard "extension" that allows you to write this. I'm pretty sure it can be switched off with some flag. Commented Feb 9, 2017 at 23:16
  • 1
    @cafekaze There's nothing wrong with using references if you actually use references. C++ virtual functions work on pointers, there's no need to use references at all if you don't want to. In many cases references help with readability and encourage the compiler to make more optimizations, so they're a good idea, but there's no rule like you're describing. I think you're coming at this with a whole lot of mistaken assumptions that are a symptom of having insufficiently robust reference material. Get the Bjarne book as a start. Commented Feb 9, 2017 at 23:17