Search code examples
c++g++static-librarieselffriend-function

Friend function access the private members of class defined in static library


I have a static library written in C++. I have also got the header files for the classes defined in the static library.

Can I access the private members of the classes defined in the static library introducing a friend function in class declaration ?


Solution

  • You mean you want to change the headers that are shipped with the library? It's in no way guaranteed that adding friend declarations there will work. You might mess up the linking part, even if your compiler says it's ok.

    Also, if those members are private, you just don't access them.