Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8912081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:06:42+00:00 2026-06-15T04:06:42+00:00

I was curious about doing this in C++: Lets say I have a small

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:06:43+00:00Added an answer on June 15, 2026 at 4:06 am

    Modifying a class declaration this way will cause incompatible code.

    The compiler needs the class declaration to figure out how much space an instance of that class takes and where in that space which member variables are located.

    If you leave out members (even private ones) in one header, code compiled with this header will assume a different layout of the class. It will allocate less space for instances of the class and will assume the member variables are in incorrect places.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a bit curious about how this works - if I have 5
I'm curious about the possibility of having a .NET class library that provides a
I have a python app that uses multiple threads and I am curious about
I am curious to know about this. whenever I write a function which have
I am curious about prevalent methodologies. I found myself doing both of these things
I'm not asking as to how go about doing this, but just curious if
Just curious about this, I have one server our dev where a ridiculous amount
Curious about running multiple xvfb displays: I have between 10-50 instances of a script
I'm curious about the correct way to architect an application that consists of the
I'm curious about what be the best way to model this for optimized performance...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.