N
N
Neusoon2020-06-20 12:18:25
C++ / C#
Neusoon, 2020-06-20 12:18:25

Is it possible in procedural programming to mimic OOP?

I am currently learning C by programming a simple game. Since a lot of manuals are written for C++, like it or not, you have to look. From OOP, I really find it convenient to create a class that holds N functions or data. For example, a scene class with functions A and B. But in C and procedural programming, I don’t understand how to do this. A stupid idea came to mind to make an additional parameter a label and divide it through conditions. Is there a more elegant way?

I like C and the procedural style. But that's when it comes to objects in the truest sense of the word. I started thinking about whether I should learn C++. So I decided to ask here about a simple thing. Which will be key in my program. I felt the meaning of the phrase "a C programmer with classes" on myself.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
U
uvelichitel, 2020-06-20
@Neusoon

Before C++ in pure C, classes were implemented as structs. Methods were imitated by including a pointer to a function in a structure field, and inheritance by including a pointer to an inherited structure.

M
Mercury13, 2020-06-20
@Mercury13

You can, and I would suggest looking at two things.
1. MiniZip. Real virtual streams written in pure C!
By the way, we have the MiniZipPort library at work, which is a stupid translation of MiniZip into virtual streams and template containers - two lines of C turned into one line on the “crosses”. In addition, to store the directory, I used the already existing self-written AccuStream (something like std:: deque, only as a stream).
2. Doom. The very first, 1993-94. They also managed to do it objectively - though by other methods.

A
Armenian Radio, 2020-06-20
@gbg

C++ can be written object, procedural, and functional. You just need to have a good knowledge of std and the behavior of classes.
When id created its masterpieces (written just in C with classes), it was hard to find good optimizing C++ compilers. Now the situation has already changed for the better - modern compilers perfectly pass the Stepanov test .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question