As another answer pointed out, there is no automatic way to do what you would like to do.
However, you can simplify the process by following coding standards.
First of all, you ask:
Main question: Is there any (semi) automatic way to do (.cpp β .h) in Visual Studio? Hotkey? Plugin?
I do not think this is the right approach. You do not want the layout of your .cpp file to control the layout of your .h file. An .h file is an interface. Layout the .h file so that it makes sense for you and your users. Then make sure that the .cpp file is laid out in a way that makes sense with the .h file.
Here is one layout for .h files that makes sense to me.
//--------------------------------------------------------------------- /*! \file MyClass.h Copyright Notice ... \author Your Name \date 2017-Mar-01 */ //--------------------------------------------------------------------- #pragma once #ifndef MyClass_H #define MyClass_H // ********** BEGIN STANDARD INCLUDES ********** // ********** END STANDARD INCLUDES ********** // ********** BEGIN EXTERN DECLARATIONS ********** // ********** END EXTERN DECLARATIONS ********** // ********** BEGIN FORWARD DECLARATIONS ********** // ********** END FORWARD DECLARATIONS ********** // ********** BEGIN TYPEDEF DEFINITIONS ********** // ********** END TYPEDEF DEFINITIONS ********** // ********** BEGIN MACRO DEFINITIONS ********** // ********** END MACRO DEFINITIONS ********** // ********** BEGIN ENUM DEFINITIONS ********** // ********** END ENUM DEFINITIONS ********** /*! \class MyClass This class does this and that. */ class MyClass { public: protected: private: }; // ********** BEGIN INLINE FUNCTIONS ********** // ********** END INLINE FUNCTIONS ********** // ********** BEGIN EXTERN FUNCTIONS ********** // ********** END EXTERN FUNCTIONS ********** #endif
And the layout for the corresponding .cpp file:
//--------------------------------------------------------------------- /*! \file MyClass.cpp Copyright Notice ... \author Your Name \date 2017-Mar-01 */ //--------------------------------------------------------------------- #include "MyClass.h" // ********** BEGIN STANDARD INCLUDES ********** // ********** END STANDARD INCLUDES ********** // ********** BEGIN EXTERN DECLARATIONS ********** // ********** END EXTERN DECLARATIONS ********** // ********** BEGIN STATIC DECLARATIONS ********** // ********** END STATIC DECLARATIONS ********** // ********** BEGIN EXTERN DEFINITIONS ********** // ********** END EXTERN DEFINITIONS ********** // ********** BEGIN HELPER CLASSES ********** // Namespace for helper classes and functions used in the file. namespace MyClassNS { } using namespace MyClassNS; // ********** END HELPER CLASSES ********** // ********** BEGIN PUBLIC FUNCTIONS ********** // ********** END PUBLIC FUNCTIONS ********** // ********** BEGIN PROTECTED FUNCTIONS ********** // ********** END PROTECTED FUNCTIONS ********** // ********** BEGIN PRIVATE FUNCTIONS ********** // ********** END PRIVATE FUNCTIONS **********
With this layout, it will be easier to make sure that the order in which function declarations appear in the .h file is in the .cpp file.
PS You donβt need to use Doxygen style markups in your code unless you use it to automate the creation of documentation.
source share