Comments (1)
几个问题:
1、“define init、define cfg、 define interface” 这几个都不是必须的,例子代码只是展示了如果你需要的时候,可以这么用,这也是例子代码的意义——尽可能的展示全部用法。
如果只是要简单继承和派生,你要用的只是
dcl_class()
def_class()
implement()
inherit()
class_internal()
而已。其它关于构造函数,析构函数,接口定义都不是必须的。
2、“我希望有个简单的OOC,让我方便继承,方便调用member function”——你可以看这篇文章 https://aijishu.com/a/1060000000291175
文章里介绍的内容是让你“按需使用”的,用到多少,就做多少,而不是为了OOC就要全部都做的。
截取文章中的一段话:
……帮助大家在偶尔需要用到“面向对象”概念的时候,能简便快捷的使用C语言“搞定”面向对象开发。
在开始后续内容之前,我们需要约定和强调一些基本原则:
- “零消耗”原则:即,我们所要实现的所有面向对象的特性都应该是“零资源消耗”或至少是“极小资源消耗”。这里的原理是:能在编译时刻(Compiletime)搞定的事情,绝不拖到运行时刻(Runtime)。
- 务实原则:即,我们不在形式上追求与C++类似,除非它的代价是零或者非常小。
- “按需实现”原则:即,对任何类的实现来说,我们并不追求把所有的OO特性都实现出来——这完全没有必要——我们仅根据实际应用的需求来实现最小的、必要的面向对象技术。
- “傻瓜化”原则:即,类的建立和使用都必须足够傻瓜化。最好所见即所得。
提示:如果你日常应用中确实没有涉及到OO的部分,完全没必要去使用PLOOC。这个模板是给那些确实需要用OO,但又必须用C语言的人使用的——意图帮助大家按照“要用多少OO特性就仅仅实现多少OO特性“的方式来部署面向对象。
3、不用传递 this 指针在原理上是做不到的。即便是 C++也只是编译器帮你做了这一步,如果你看汇编会发现,C++仍然在每个方法调用的时候,用第一个参数传递了this指针。遗憾的是C语言无法做到这一点。
如果还有什么疑问,可以在这里留言。
from plooc.
Related Issues (12)
- class_internal / protected_internal 后面跟参数的意义? HOT 1
- IMPLEMENT 和 INHERIT 的区别是? HOT 1
- end_def_class 必须写 ? HOT 1
- declare_class 在头文件中使用的必要性是什么? HOT 1
- union类型在这里起到了什么样的作用? HOT 1
- compile cpp source code(__OOC_CPP__ is defined) failed on arm-none-eabi-g++ 2021.10 HOT 1
- compile cpp source code(__OOC_CPP__ is defined) failed on arm-none-eabi-g++ 2021.10 HOT 1
- Open Github Discussions HOT 1
- How to compile the examples? HOT 6
- Comparison with other solutions? HOT 1
- What is the difference between the class templates? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plooc.