When should auxiliary functions be class members?

I have the following question, if there are 2 classes that consist of a private variable of type std::map , and a constructor that reads data from a save file with the help of a function, which of the following 2 examples would be considered correct or "better":

A.h
1
2
3
4
5
6
7
8
class A{
private:
    std::map < int, int > the_map;
    void read_from_file();

public:
    A();
}


A.cpp
1
2
3
4
5
6
7
8
9
10
11
A::A()
{
    // whatever goes here

    read_from_file():
}

A::read_from_file()
{
    // reads from file into the_map
}


where the auxiliary function is declared as a private member, or example B:

B.h
1
2
3
4
5
6
7
class B{
private:
    std::map < int, int > the_map;

public:
    B();
}


B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
read_from_file(std::map < int, int >& map);

B::B()
{
    // whatever goes here

    read_from_file(the_map):
}

read_from_file(std::map < int, int >& map)
{
    // reads from file into map
}


where the auxiliary function is not a member function, I find this worrying because with a large class where there are a lot of functions that might need to modify private members, the .h file might get too cluttered, but the little things I know about good coding practices tell me that functions that modify private members should either be members or friends (a third idea that just occurred to me).
Last edited on
Topic archived. No new replies allowed.