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 8306453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:20:03+00:00 2026-06-08T18:20:03+00:00

How can I make visible variables/functions in particular files? For example, lets say I

  • 0

How can I make visible variables/functions in particular files?
For example, lets say I have this hierachy of files:

a.h

extern int var;

a.cpp

#include "a.h"

int var;

b.h

#include "a.h"

void function();

b.cpp

#include "b.h"

void function() {
    var = 0;
}

in main.cpp I want to be able call function(), but not to access var variable

#include "b.h"

int main(int argc, char** argv) {
    function(); /* possible to call */
    var = 0 /* var shouldn't be visible */
} 

I don’t want file a.h to be included in main.cpp – only b.h. How can I achieve this?

  • 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-08T18:20:03+00:00Added an answer on June 8, 2026 at 6:20 pm

    a.h doesn’t need to be included in b.h, only b.cpp. This is because var is only needed by the function definition, not its declaration. This goes along with the rule not to include headers in other headers unless you absolutely have to.

    b.h

    void function();
    

    b.cpp

    #include "b.h"
    #include "a.h"
    
    void function() {
        var = 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this div : <div style=overflow:auto;></div> How can I make the scrollbars visible only
Can any one tell me how can I make divs visible in ASP.NET. I
I can make a variable's name from two variables' value: $a = 'tea'; $b
I can make batch or vbs file on windows and run. this can automate
Can someone tell me how I can make the following output? I have a
I come from the Java world, where you can hide variables and functions and
How can I make the JButton visible? 1) When no progressive background is turned
how can I make code generated or changed by jQuery (JavaScript) visible? Showing the
In C#, can you make a class visible only within its own namespace without
If I have a UIView (or UIView subclass) that is visible, how can I

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.