{"id":32787,"date":"2023-09-14T17:21:05","date_gmt":"2023-09-14T17:21:05","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=32787"},"modified":"2023-11-03T18:07:04","modified_gmt":"2023-11-03T18:07:04","slug":"make-member-function-const-and-global-function-static-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/make-member-function-const-and-global-function-static-in-visual-studio\/","title":{"rendered":"Make Member Function const and Global Function Static in Visual Studio"},"content":{"rendered":"<p><span class=\"TextRun SCXW28857402 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW28857402 BCX8\" data-ccp-parastyle=\"Normal (Web)\">We are delighted to announce that Visual Studio Preview now includes the &#8220;Make Member Function Const&#8221; and &#8220;Make Global Function Static&#8221; features. To check out these features, make sure you update to the latest version of\u202f<\/span><\/span><a class=\"Hyperlink SCXW28857402 BCX8\" href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"TextRun Underlined SCXW28857402 BCX8\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW28857402 BCX8\" data-ccp-charstyle=\"Hyperlink\">Visual Studio Preview<\/span><\/span><\/a><span class=\"TextRun SCXW28857402 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW28857402 BCX8\" data-ccp-parastyle=\"Normal (Web)\">.<\/span><\/span><span class=\"EOP SCXW28857402 BCX8\" data-ccp-props=\"{&quot;134233117&quot;:true,&quot;134233118&quot;:false,&quot;201341983&quot;:0,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<p><div  class=\"d-flex justify-content-center\"><a class=\"cta_button_link btn-primary mb-24\" href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\" target=\"_blank\">Download Visual Studio Preview <\/a><\/div><\/p>\n<h3><span class=\"TextRun SCXW199985640 BCX8\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW199985640 BCX8\" data-ccp-parastyle=\"heading 1\">Make Member Function Const<\/span><\/span><\/h3>\n<p>Visual Studio now generates hints to mark member functions as <code>const<\/code> when a member function doesn&#8217;t modify the object&#8217;s state. This feature identifies cases where a member function performs actions that could be accomplished through the object&#8217;s public interface using a const pointer.<\/p>\n<p>We have made this process easier for you by adding a suggestion that allows you to make a member function const. When a member function can be made const, there will be a suggestion (indicated by three dots) below the function. Hovering over them will inform you that &#8220;the member function can be made const,&#8221; and you can click on the light bulb to make the member const.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/make_const.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-32788\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/make_const.gif\" alt=\"Image make const\" width=\"2069\" height=\"901\" \/><\/a><\/p>\n<p>When you make a member function const, the change is applied to all the files that have the member function. You can preview all the changed files by selecting the &#8220;Preview all changed files&#8221; link.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Make-function-const-in-multi-file.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-32800\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Make-function-const-in-multi-file.gif\" alt=\"Make function const in multi file GIF\" width=\"2394\" height=\"1302\" \/><\/a><\/p>\n<p><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-parastyle=\"Normal (Web)\">&#8220;Make Member Function Const&#8221; is on by default, and <\/span><span class=\"NormalTextRun CommentStart SCXW9364774 BCX8\" data-ccp-parastyle=\"Normal (Web)\">it is set as suggestion<\/span><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-parastyle=\"Normal (Web)\">. The setting can be found and configured by navigating to <\/span><\/span><strong><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-charstyle=\"Strong\">Tools<\/span><\/span><\/strong><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-parastyle=\"Normal (Web)\"> &gt; <\/span><\/span><strong><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-charstyle=\"Strong\">Options<\/span><\/span><\/strong><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-parastyle=\"Normal (Web)\"> &gt; <\/span><\/span><strong><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-charstyle=\"Strong\">Text Editor<\/span><\/span><\/strong><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-parastyle=\"Normal (Web)\"> &gt; <\/span><\/span><strong><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-charstyle=\"Strong\">C\/C++<\/span><\/span><\/strong><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-parastyle=\"Normal (Web)\"> &gt; <\/span><\/span><strong><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-charstyle=\"Strong\">Code Style<\/span><\/span><\/strong><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-parastyle=\"Normal (Web)\"> &gt; <\/span><\/span><strong><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-charstyle=\"Strong\">Linter<\/span><\/span><\/strong><span class=\"TextRun SCXW9364774 BCX8\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW9364774 BCX8\" data-ccp-parastyle=\"Normal (Web)\">.<\/span><\/span><span class=\"EOP SCXW9364774 BCX8\" data-ccp-props=\"{&quot;134233117&quot;:true,&quot;134233118&quot;:false,&quot;201341983&quot;:0,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Member-Function-Can-be-Made-Const-Setting.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-32794\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Member-Function-Can-be-Made-Const-Setting.png\" alt=\"Make Member Function Const Setting\" width=\"1801\" height=\"1322\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Member-Function-Can-be-Made-Const-Setting.png 1801w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Member-Function-Can-be-Made-Const-Setting-300x220.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Member-Function-Can-be-Made-Const-Setting-1024x752.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Member-Function-Can-be-Made-Const-Setting-768x564.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Member-Function-Can-be-Made-Const-Setting-1536x1127.png 1536w\" sizes=\"(max-width: 1801px) 100vw, 1801px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Make Function Static<\/h3>\n<p>In Visual Studio Preview, you&#8217;ll now receive hints to mark global functions as <code>static<\/code>. When encountering a global function that doesn&#8217;t have a forward declaration in a header file, you will be able to make the function static effortlessly. We already have a feature that detects global functions and suggests creating forward declarations, and now we have added an option to mark them as static. This feature works smoothly with modern C++ projects, as it doesn&#8217;t provide suggestions for functions within anonymous namespaces. Static global functions are accessible within the translation unit where they are defined.<\/p>\n<p>When there is a global function that doesn&#8217;t have a forward declaration, it will have a suggestion. Hovering over the suggestion will reveal a screwdriver icon, signaling that the function can be made static. You can complete the process\u00a0by clicking the screwdriver icon and selecting &#8220;Make this function static.&#8221;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/make_-function_static.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-32795\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/make_-function_static.gif\" alt=\"Image make function static\" width=\"2146\" height=\"645\" \/><\/a><\/p>\n<p>You can configure this feature&#8217;s setting in <strong>Tools<\/strong> &gt; <strong>Options<\/strong> &gt; <strong>Text Editor<\/strong> <strong>&gt; C\/C++<\/strong> &gt; <strong>IntelliSense<\/strong>. While the default tag is set as a suggestion, you have the flexibility to customize the severity level to none, warning, or error.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Make-global-function-static-setting.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-32796\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Make-global-function-static-setting.png\" alt=\"Make global function static setting.\" width=\"737\" height=\"660\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Make-global-function-static-setting.png 737w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/09\/Make-global-function-static-setting-300x269.png 300w\" sizes=\"(max-width: 737px) 100vw, 737px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><span lang=\"EN-US\">Send us your feedback<\/span><\/h3>\n<p>To experience this exciting new feature, make sure to download the <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">latest version of Visual Studio Preview<\/a>. Your feedback is of utmost importance to us, as it guides the enhancement of Visual Studio. Please share your insights in the comments section, the <a href=\"https:\/\/developercommunity.visualstudio.com\/cpp\">developer community<\/a>, or on Twitter (<a href=\"https:\/\/twitter.com\/visualc\">@VisualC<\/a>). Alternatively, you can also reach out to us via email at <a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are delighted to announce that Visual Studio Preview now includes the &#8220;Make Member Function Const&#8221; and &#8220;Make Global Function Static&#8221; features. To check out these features, make sure you update to the latest version of\u202fVisual Studio Preview.\u00a0 Make Member Function Const Visual Studio now generates hints to mark member functions as const when a [&hellip;]<\/p>\n","protected":false},"author":96741,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-32787","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>We are delighted to announce that Visual Studio Preview now includes the &#8220;Make Member Function Const&#8221; and &#8220;Make Global Function Static&#8221; features. To check out these features, make sure you update to the latest version of\u202fVisual Studio Preview.\u00a0 Make Member Function Const Visual Studio now generates hints to mark member functions as const when a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/32787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/96741"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=32787"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/32787\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=32787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=32787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=32787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}