Using "super" in C : A Non-Standard Yet Practical Approach
In C , the lack of a dedicated "super" keyword to access the base class has led to inventive solutions such as using a typedef'd "super." This technique allows developers to create an alias for the base class, enabling them to call base class methods and constructors with ease.
Commonality and Acceptability
While the use of typedef "super" is not common in all codebases, it is not uncommon either. It is a particularly useful technique when the base class is verbose or templated. Some developers find it enhances code readability and reduces the likelihood of errors.
Pros and Cons
Pros:
Cons:
Should "super" Be Standardized?
The ISO C Standards committee has considered standardizing a "super" keyword in the past. However, due to concerns about complexity and the existence of alternative solutions such as typedef "super," this has not yet been implemented.
Alternatives to typedef "super"
Aside from using a typedef, there are also other ways to achieve similar functionality:
Conclusion
While the use of typedef "super" is not a standard feature in C , it offers many benefits in terms of code readability and ease of use. Its non-standard nature is a potential drawback, but this can be mitigated by using it responsibly and potentially placing it in a non-public section of the class.
The above is the detailed content of Should C Standardize a 'super' Keyword for Base Class Access?. For more information, please follow other related articles on the PHP Chinese website!