C++ - Distributing different headers than development

Posted by Ben on Stack Overflow See other posts from Stack Overflow or by Ben
Published on 2012-11-30T17:02:25Z Indexed on 2012/11/30 17:03 UTC
Read the original article Hit count: 165

Filed under:
|

I was curious about doing this in C++:

Lets say I have a small library that I distribute to my users. I give my clients both the binary and the associated header files that they need. For example, lets assume the following header is used in development:

#include <string>

ClassA 
{
    public:
        bool setString(const std::string & str);

    private:
        std::string str;
};

Now for my question. For deployment, is there anything fundamentally wrong with me giving a 'reduced' header to my clients? For example, could I strip off the private section and simply give them this:

#include <string>

ClassA 
{
    public:
        bool setString(const std::string & str);
};

My gut instinct says "yes, this is possible, but there are gotchas", so that is why I am asking this question here. If this is possible and also safe, it looks like a great way to hide private variables, and thus even avoid forward declaration in some cases.

I am aware that the symbols will still be there in the binary itself, and that this is just a visibility thing at the source code level.

Thanks!

© Stack Overflow or respective owner

Related posts about c++

Related posts about header