When to use class and when functions?

When I want to solve a programming solution, when should I use class and when should I use function? In C++ are there any standards for this?

Hi,

Well the basic idea of a class is to group together closely related data, and provide class functions which deal with that data, so I am not sure what you mean - it's not really one or the other.

The concept of a class is a main component of the OOP paradigm - one makes objects from classes. There are lots of different things which come from that, like passing messages between objects, polymorphism, design patterns etc.

Hope all goes well :+)
Those two are orthogonal, they are not replacement to each other. Generally class either contains member functions or there are standalone functions operating on class instances.

Generally, if you need to implement a single action, without saving any persistent data, you want a function: find a greatest common divisor, sum all numbers in array.

If you have an entity with persistent data and some inherent behavior, if you need to save some state in addition to some actions, you want a class.
thanks, it seems i need to use function for this problem I got..its about reading ports...

filter 3000 //read port 3000

Topic archived. No new replies allowed.