Hello

When you have particular function (which is just one) in more classes that does the same thing with some specific element (member) what approach do you take to solve that problem?

For instance if I have 2 classes with the same function (that does the same thing with somedata object):

Code:
class first_class {
public:
  void some_function();
 
public:
  datatype somedata;
};

class second_class {
public:
  void some_function();
 
public:
  datatype somedata;
};
What approach would you use in such cases to profesionalize and minimize the code?

Should I make new class with this function and derive from it?
Or would it be better to make global function that accepts somedata as a reference?
Is there any better approach?

Many thanks in advance!