Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always create classes in C++? [closed]

Coming from a Java background it is new for me to deal with the choice of creating a class or just implementing the functions I might need. Normally this is no question when it comes to modeling something which could have a state.

Now I am implementing a shared library which has no main function and exclusively static member functions. Does something speak against creating a class to encapsulate the functions?

Further I wanted to encapsulate further code, especially auxillary functions, in another file. The execute code is always the same and the state of it does not change, so I guess I would declare them also static - so the same questions arises here to.

like image 297
Konrad Reiche Avatar asked Apr 19 '11 19:04

Konrad Reiche


People also ask

Can we create classes in C?

This document describes the simplest possible coding style for making classes in C. It will describe constructors, instance variables, instance methods, class variables, class methods, inheritance, polymorphism, namespaces with aliasing and put it all together in an example project.

Why are there no classes in C?

C mostly uses functional/structural programming instead of implementing Object Oriented Programming as in languages like C++ , Java , Python etc. which use classes .

What is the alternative to class for C?

There is nothing equivalent to classes . Its a totally different paradigm. You can use structures in C. Have to code accordingly to make structures do the job.


1 Answers

If you find you have a class where every method is static, then perhaps a namespace would be more appropriate.

like image 183
chrisaycock Avatar answered Oct 21 '22 19:10

chrisaycock