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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:57:50+00:00 2026-05-28T22:57:50+00:00

I am trying to get objects to reference a few globalized variables (before you

  • 0

I am trying to get objects to reference a few globalized variables (before you start hitting me for using globals putting them into an object would either make it unreachable by other objects, or require adding excess arguments to method calls) for example

main.cpp

bool firstLoop;
const int dt = 10;

thing.cpp

void thing::Update(Object * thingToUpdate){
    if( firstLoop){
        ...
    } else{
        // working with dt
    }
}

but every time I try to access the variables I get a error of “undeclared identifier”
do I need to mark them as extern, or something else.

  • 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-28T22:57:50+00:00Added an answer on May 28, 2026 at 10:57 pm

    In thing.cpp, write

    extern bool firstLoop;
    

    Note that the same trick will not work for dt because it has internal linkage(because it’s a const variable of built-in type).

    Usually, you should have one header file where you declare(with extern) your variables that need access from everywhere, and another source file which defines these variables. The constant variables of built-in type should be defined in the header file, or their linkage should be explicitly made external by means of the selfsame extern keyword. Then the header file should be included everywhere where access is needed. Example:

    //Globals.h
    
    extern char ec;
    extern const char ecc;
    const char cc = 'a';
    
    //Globals.cpp
    char ec /* = 'b'*/;
    extern const char ecc = 'b';
    //no need to do anything with cc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get my head around mutable vs immutable objects. Using mutable objects
I'm trying to get client-side javascript objects saved as a file locally. I'm not
I'm trying to get an object element from my webpage using getElementById (ultimately so
I'm having a bit of trouble trying to get class variables to work in
I am trying to track objects inside an image using histogram data from the
Today I was trying to wrap my head around immutable objects that reference each
Im trying to get a list of line items to a webpage using JSON,
Trying to use: :On Error exit :r D:\opt\db_objects\REPORTS\dbo.sp_ReportCountLORUsers.sql ...and I get: Msg 102, Level
iam trying to get all object's xpath's from loaded page via selenium something similar
I am trying to get a MethodInfo object for the method: Any<TSource>(IEnumerable<TSource>, Func<TSource, Boolean>)

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.