The C/C++ extension for Visual Studio Code offers developers a new feature that, according to Microsoft, has often been requested by many. By automatically creating definitions or declarations in functions, you should now be able to quickly create a declaration in a header file for a function for which the developer only has one definition.
No more constant copying, pasting and checking
Of course, this also works the other way around: developers can also have a definition created automatically if they don’t have a declaration. In a blog article, the development team at Microsoft emphasizes that these generated definitions and declarations already contain all function arguments, so that constant copying, pasting and checking is no longer necessary.
Programmers should now be able to easily create such a definition: just click on their class function definition and then on the code action (light bulb icon).
After selecting Code Action (lightbulb icon) a drop down menu opens where developers can then select “Create a Declaration”.
(Image: Microsoft)
After that, all you have to do is select the function declaration and then the code action “Create definition” for the function. Definitions and declarations are created based on the patterns that developers have already established in their code. For example, if the definition is between the Addition() and Subtraction() functions in Math.cpp and a declaration is asked for, it will be recreated between the Addition() and Subtraction() declarations.
If declarations or definitions were defined in a file other than the source file, the program follows the general convention: If the developer chose the case in which the names of the header and source file match, the program will also find this file if the header file was not included in the source file. In these cases, the header file is automatically included in the source file once the declaration or definition has been added.
This functionality applies not only to classes, but also to namespaces. If a function template is declared in a header file, then the definition of this function template is also created in the same header file. This also applies to non-template member functions of class templates.
The blog entry provides more information and examples of these new features in the C/C++ Extension for Visual Studio Code.
(fms)
To home page