mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'doc/minor_cxx_additions' into 'master'
doc: small changes for cxx code style See merge request espressif/esp-idf!7210
This commit is contained in:
commit
da8c06eafc
@ -194,7 +194,7 @@ The same rules as for C apply. Where they are not enough, apply the following ru
|
|||||||
|
|
||||||
File Naming
|
File Naming
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
C++ Header files have the extension ``.h``. C++ source files have the extension ``.cpp``, which is important for the compiler to distiguish them from normal C source files.
|
C++ Header files have the extension ``.hpp``. C++ source files have the extension ``.cpp``. The latter is important for the compiler to distiguish them from normal C source files.
|
||||||
|
|
||||||
Naming
|
Naming
|
||||||
^^^^^^
|
^^^^^^
|
||||||
@ -202,11 +202,39 @@ Naming
|
|||||||
* **Class and struct** names shall be written in ``CamelCase`` with a capital letter as beginning. Member variables and methods shall be in ``snake_case``.
|
* **Class and struct** names shall be written in ``CamelCase`` with a capital letter as beginning. Member variables and methods shall be in ``snake_case``.
|
||||||
* **Namespaces** shall be in lower ``snake_case``.
|
* **Namespaces** shall be in lower ``snake_case``.
|
||||||
* **Templates** are specified in the line above the function declaration.
|
* **Templates** are specified in the line above the function declaration.
|
||||||
|
* Interfaces in terms of Object-Oriented Programming shall be named without the suffix ``...Interface``. Later, this makes it easier to extract interfaces from normal classes and vice versa without making a breaking change.
|
||||||
|
|
||||||
Member Order in Classes
|
Member Order in Classes
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
In order of precedence:
|
||||||
|
|
||||||
First put the public members, then the protected, then private ones. Omit public, protected or private sections without any members.
|
* First put the public members, then the protected, then private ones. Omit public, protected or private sections without any members.
|
||||||
|
* First put constructors/destructors, then member functions, then member variables.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
class ForExample {
|
||||||
|
public:
|
||||||
|
// first constructors, then default constructor, then destructor
|
||||||
|
ForExample(double example_factor_arg);
|
||||||
|
ForExample();
|
||||||
|
~ForExample();
|
||||||
|
|
||||||
|
// then remaining pubic methods
|
||||||
|
set_example_factor(double example_factor_arg);
|
||||||
|
|
||||||
|
// then public member variables
|
||||||
|
uint32_t public_data_member;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// first private methods
|
||||||
|
void internal_method();
|
||||||
|
|
||||||
|
// then private member variables
|
||||||
|
double example_factor;
|
||||||
|
};
|
||||||
|
|
||||||
Spacing
|
Spacing
|
||||||
^^^^^^^
|
^^^^^^^
|
||||||
|
Loading…
x
Reference in New Issue
Block a user