0

If I ask Visual Studio 2017 to generate an implementation for me using this button:

enter image description here

The result will be:

void MyClass::testMethod(int * someParameter) const
{
}

Notice that the * is not next to type. In our project, we put & and * next to types. This is what Bjarne Stroustrup prefers as well:

A "typical C++ programmer" writes int* p; and explains it "p is a pointer to an int" emphasizing type. Indeed the type of p is int*. I clearly prefer that emphasis and see it as important for using the more advanced parts of C++ well.

Is there a setting for formatting the generated methods so that they are consistent with this formatting style?

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • 1
    Do you have [pointer declaration formatting settings](https://i.stack.imgur.com/yFP0H.png) set up properly? I should mention that I wouldn't recommend this style, because it is just inconsistent: why keep some parts of the type not space-separated while others must be space-separated? `unsigned int const*const* foo` Also note that `int* p` in the context of that quote can be opposite to `int *p`, not to `int * p`. `int *p` makes a sense in C, where `*p` would yield an `int` but with introduction of references in C++ that symmetry is lost and with `int &p` writing `&p` won't yield `int`. – user7860670 Sep 10 '19 at 14:33
  • I would definitelly write `const unsigned int* const* foo` instead of what you did. I never had to though. Anyway, I am missing the setting in your screenshot. I looked in the same part of the settings before asking, and the pointer/refference settings are simply not there. The others that I can see in the screenshot are present. – Tomáš Zato Sep 10 '19 at 14:37
  • Hmm, I guess these settings are from VS2019. They did add some new formatting options which probably could help with this matter. Writing `const unsigned int* const * foo` is even more inconsistent, not just spacing but exceptional `const` qualifier placement as well... – user7860670 Sep 10 '19 at 14:42

0 Answers0