Generate C++ class with header and source file, and generate getters and setters for class members ! Also generate tasks.json for C++ compilation with include path of all source files in the task !
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
GenClass is a Visual Studio Code extension that allows you to quickly generate a C++ class along with its .h and .cpp files. This extension saves you time by automating the creation of these files directly within the VS Code file explorer.
Features
Generates a header file (.h) and a source file (.cpp) for a new C++ class.
Automatically adds the class constructor and destructor.
Uses the selected folder in the explorer to create the class files.
Accessible via the context menu (right-click) in the file explorer.
Automatically adds author and date information to the generated files.
Automatically includes the class header file in the source file.
Generates getter and setter methods for all member variables in the class.
Generates basic tasks.json file for including the all .cpp files in the compilation and laucnh a run without debug or debug mode (configurable).
How to Use
In Explorer
Right-click on a folder in the VS Code file explorer.
Select the "Create C++ Class" option from the context menu.
An input box will appear, prompting you to enter the class name.
The extension will automatically generate the .h and .cpp files in the selected folder with the following basic structure shown in the example section.
In File
Right-click in the editor window.
Select the "Create C++ Class" option from the context menu.
An input box will appear, prompting you to enter the class name.
The extension will automatically generate the .h and .cpp files in the same folder as the current file with the following basic structure shown in the example section.
An input box will appear asking if you want to include the header file in the source file.
Generate Getters and Setters
Open the header file (.h) of your class in the editor.
Right-click in the editor window.
Select the "Generate Getters and Setters" option from the context menu.
The extension will automatically generate getter and setter methods for all member variables declared in the class, avoiding any duplicates.
Generate Tasks.json
Right-click in your main file (.cpp) in the editor window.
Select the "Generate Tasks.json" option from the context menu.
The extension will automatically generate a tasks.json file
And run your amazing code !
Example of Generated Class
Class Name : MyClass
MyClass.h
/* --- MyClass.h --- */
/* ------------------------------------------
author: {Your Username}
date: {Current Date}
------------------------------------------ */
#ifndef MYCLASS_H
#define MYCLASS_H
class MyClass {
public:
MyClass();
~MyClass();
int getValue(); // Example getter
void setValue(int v); // Example setter
private:
int value; // Example member variable
};
#endif // MYCLASS_H