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

  • Home
  • SEARCH
  • 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 8253313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:50:18+00:00 2026-06-08T00:50:18+00:00

Possible Duplicate: In C++ why have header files and cpp files? I don’t quite

  • 0

Possible Duplicate:
In C++ why have header files and cpp files?

I don’t quite get C++ header files, for two conflicting reasons:

  1. I thought the purpose of header files was in general to separate interface and implementation. In other words, the client uses the header file to learn how to use the class, but doesn’t have to worry about how the class actually implements this functionality internally.

  2. Why, then, are private variables of a C++ class specified in its header file?

It seems to me that having private variables in the header file violate the separation of interface and implementation. Intuitively, I would think it would make more sense for private variables to be in the source file, since this is the file that is not exposed to the outside world.

Maybe I’m just misunderstanding the purpose of header files, and 1. above is just completely wrong? In what ways?

  • 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-08T00:50:20+00:00Added an answer on June 8, 2026 at 12:50 am

    C++ distinguishes between declaration and definition of functions and classes. In general a C++ header file contain the declaration of a class. Since no partial declarations are allowed the header file needs to contain the complete class declaration including all private members (variables and member functions).

    If you want to hide the complete implementation from the public you can use the pimpl idiom to achieve this.

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

Sidebar

Related Questions

Possible Duplicate: Why does this integer division yield 0? I have a C header
Possible duplicate : comparing-two-arrays I have two NSArray and I'd like to create a
Possible Duplicate: If I have two tables in SQL with a many-many relationship, do
Possible Duplicate: C++ Header order My question is about includes in .h files. Is
Possible Duplicates: [C] Header per source file. In C++ why have header files and
Possible Duplicate: .NET & Tab-Delimited files I have a list that has 2 columns:
Possible Duplicate: get the value of an url response with curl I have an
Possible Duplicate: Why do I get “Cannot redirect after HTTP headers have been sent”
Possible Duplicate: PHP error: Cannot modify header information – headers already sent I have
Possible Duplicate: <header> vs. <head> Do I have to use <div class=header> as <header>

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.