I wanted to create a class where it could be accessed in the library I created, how can I declare the class as private and can be called only in the library?
I wanted to create a class where it could be accessed in the library I created, how can I declare the class as private and can be called only in the library?
You can not do this in C ++.
In fact, in no language is there definite protection to avoid use. When there is some protective measure in accessing some part of the code it only works if the programmer does not insist. It is not protection in the sense of prohibiting, but inhibiting. You have made the library available to access it.
In languages such as C # that have an internal level of visibility that inhibits external members from calling that class, there is nothing to prevent it from being called. C ++ does not even have this.
If this is enough it is simple to solve. Do not provide the files with prototypes that are needed for anyone to use them to compile the code.
In fact not documenting the class publicly is usually enough to avoid external use.
Depending on the desired sophistication you can choose the Pimpl language .