面向对象的ANSI C? [英] Object Oriented ANSI C?
问题描述
可能重复:结果
你会写面向对象code用C <? / A>
块引用>您好,
我不知道是否有可能使用严格的ANSI C作为一种面向对象的语言。如果有可能,我该如何使ANSI C. Allthough类的语言是不适合面向对象的,我真的很渴望尝试。
任何示例,链接等都是AP preciated。
由于提前,
马尼克斯面包车莱斯韦克。
解决方案一个结构可以容纳这样
方法和变量
结构myStructFoo {
Foobar的诠释();
INT privFooBar;
};那你是怎么得出一个面向对象的东西用普通的旧ANSI C编译器,如果你想学用C全OOP ++你将与一个ANSI C ++编译器有良好表现,因为这是你需要一个更好的选择。使用C语言....看它这样,相信你可以使用一个结构使用对象..as面向对象的风格,但名称不完全是... ...直观作为
结构
更举办领域,是不可分割的数据结构,例如链表,栈,队列等的一部分,如果你有一个ANSI C ++编译器,这是它的样子:
类myFoo {
上市:
Foobar的诠释();
私人的:
INT privFooBar;
};比较看,信息隐藏通过
公共
和私人
关键字。<规定它的显示更直观/ p>Possible Duplicate:
Can you write object oriented code in C?Hello,
I'm wondering if it's possible to use strict ANSI C as a object oriented language. And if it's possible, how do I make a class in ANSI C. Allthough the language isn't designed for OO, I'm really eager to try this.
Any examples, links etc. are appreciated.
Thanks in advance,
Marnix van Rijswijk.
解决方案A struct can hold methods and variables such that
struct myStructFoo{ int fooBar(); int privFooBar; };That is how you derive an OO "thing" using a plain old ANSI C compiler, if you want to learn the full OOP with C++ you will fare better with an ANSI C++ compiler as that is a better fit for your needs...as the OOP style using a C language is.... look at it this way, sure you can use a object using a struct, but the name is not exactly...intuitive...as a
struct
is more for holding fields and is part of integral data structures such as linked list, stacks, queues etc. If you had an ANSI C++ Compiler, this is how it would look:class myFoo{ public: int fooBar(); private: int privFooBar; };Compare and see how it appears more intuitive, information hiding is specified via the
public
andprivate
keywords.这篇关于面向对象的ANSI C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!