Inheritance TypeĬMake uses somewhat similar inheritance concepts to C++, especially for the C++ public and private access specifiers and inheritance types. Public and protected members of the base class become private members of the derived class.Īlternatively, this could be described using the following simplified table. Public and protected members of the base class become protected members of the derived class. A base class’s private members are never accessible directly from a derived class, but can be accessed through calls to the public and protected members of the base class. Public members of the base class become public members of the derived class and protected members of the base class become protected members of the derived class. When it comes to class inheritance, there are also three types of inheritances. Members cannot be accessed (or viewed) from outside the class.Īlternatively, this could be described using the following simplified table. However, they can be accessed in inherited classes. Members cannot be accessed from outside the class. Members are accessible from outside the class. In C++ object oriented programming, there are three types of access specifiers for classes. So in this blog post, I would like to discuss some of my thoughts on these CMake keywords from the perspective of “inheritance”. Today, I read Kuba Sejdak’s blog post “Modern CMake is Like Inheritance” and I found his interpretation on the CMake keywords PUBLIC, PRIVATE, and INTERFACE inspiring. However, it is certainly not best practice. So when I was building my C/C++ projects using CMake, I often just use PUBLIC everywhere or leave the keyword blank (CMake will then use PUBLIC by default), the libraries and executables built from the projects would work in most of the scenarios. When it comes to target_include_directories and target_link_libraries, there are several keywords, PUBLIC, PRIVATE, and INTERFACE, that I got confused about from time to time even if I have read the related official documentations. CMake is one of the most convenient building tools for C/C++ projects.
0 Comments
Leave a Reply. |