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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:37:58+00:00 2026-05-24T18:37:58+00:00

In my code, due to efficiency consideration, I place a long function in it’s

  • 0

In my code, due to efficiency consideration, I place a long function in it’s own file (let’s name it a.cpp). I have also created a second file named b.cpp which holds another function which uses the same variables names.

I have tried to create a header file for those variables but it didn’t work. Is there a way to do that (apart from placing the functions in the same file)?

A simple example:

a.cpp

double s;

void a(){
  s = 1.0;
  printf("%f\n",s);
}

b.cpp

double s;

void b(){
  s = 2.0;
  printf("%f\n",s);
}

Note
Each of those file is, in effect a c but the whole program is c++.

  • 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-05-24T18:37:59+00:00Added an answer on May 24, 2026 at 6:37 pm

    Write extern double s; in both (or in a header). This is a declaration without being a definition.

    Then write double s; in just one .cpp file — this is where the double object will physically “live”.

    More here.

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

Sidebar

Related Questions

I have following code that does not work due to a being a value
Code I have: cell_val = CStr(Nz(fld.value, )) Dim iter As Long For iter =
Hey, long story short I have inherited some terrible code. As a result a
It has been a while since I have wrote any code due to military
I am here due to a strange behaviour in Button_Click event. The code is
I'm having some issues with my code. This is probably due to some design
Assuming A.sql contains the following code, then second Select query won’t be executed due
I'm trying to delete an int[] from an ArrayList. Due to my code I
I'm working on updating a project which uses the following code to place a
I have a function which calls a users associated users from a table. The

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.