r/C_Programming • • Jul 17 '26

C with classes

I'm curious to know: who uses some C++ features when coding in C? And what feature(s) are you using?

29 Upvotes

79 comments sorted by

View all comments

Show parent comment

3

u/Bros2316 Jul 18 '26

I have always recommended beejs guides for almost everything and it’s no different here. I would argue that if you don’t have the concept of pointers down, I wouldn’t start trying to tackle a “class” implementation.

For classes though, you would use struct in c. For example, I may have struct named Person. That person has a member of char * name, int age, and void(dance*)(void). dance is a function pointer that during the initialization of my “object” I would set to a function of specific choosing. These custom functions could be static, so each class has their own if we decided to create multiple people with difference dances, however all would be called by using the Person->dance.

I would make this cleaner but I’m on mobile, sorry.

2

u/ghost_ware Jul 18 '26

No worries, I appreciate it! I'm good with pointers and structs. I'll take a look at that guide. ty!