Write C and OO

xiaoxiao2021-03-06  37

I used to see someone writing c to oo, but the article always doesn't know the cloud, don't learn something, in fact, many C processes are also developed by OO's idea. So I summarize and I hope to discuss the OO method of C.

C is actually a very free language, while oo is a kind of thinking, and it is also a limit, as long as you add this limit in C, you can achieve a certain degree of OO.

For example, the most important thing in OO is package. The biggest feature of C is open. But if there is a packaged thought to write C, it is not possible.

In C , our class is said (with class a):

Class A

{

PUBLIC:

Function1 ();

Function2 ();

Private:

INT I;

Int J;

}

And I want to write such a package code with C (I can only say that there is a clear sign) is this:

Struct C_A_

{

INT I;

Int J;

}

TYPEDEF C_A_ A;

CA_Function1 (A *, other parameters);

CA_Function2 (A *, other parameters);

When you use it, you will have a big problem.

Then inherit, we must of course use a simple way to complete C so powerful inheritance, but it is not difficult to do inheritance, such as:

Struct C_B_

{

A a a;

Int m;

Int n;

}

TYPEDEF C_B_B;

CB_Function1 (b *, other parameters);

CB_Function2 (b *, other parameters);

Use when you are using a function:

CA_Function1 (& (B.A), other parameters);

CA_Function2 (& (B.A), other parameters);

This is just two major problems, but the polymorphic problem is not easy to think about the solution. Please discuss this feasibility of this visit.

I think OO is actually a way. We can also write a very OO C code without technical support.

转载请注明原文地址:https://www.9cbs.com/read-67869.html

New Post(0)