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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:06:33+00:00 2026-06-17T07:06:33+00:00

I am working on a small project that has two modules and a header

  • 0

I am working on a small project that has two modules and a header file.

In one of my modules I create a vector of strings and populate it with some data.

I am now having problems with accessing the vector values in my other module. could anyone offer me any advice on how to make this global?

Please don’t think I am lazy/not tried sorting this myself, i am just confused with #ifndef’s, #includes, #define, extern’s and when/where to declare function prototypes. I know all these have something to do with it, just not sure about the order! I am using VS 2010.

  • 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-17T07:06:34+00:00Added an answer on June 17, 2026 at 7:06 am

    Define an API function in your module which returns a reference to your vector and use that function in your other modules.

    file1.h

    vector<string>& getMyVector();
    

    file1.cpp

    vector<string> myVector;
    
    vector<string>& getMyVector() { return myVector; }
    

    So, in the other module (file2.cpp) you just:

    #include "file1.h"
    
    ...
    
    cout << "First element of my vector is:" << getMyVector()[0] << endl;
    

    Hopefully, you don’t want to use it in a multithreaded environment, otherwise you would need to implement it as a proper singleton.

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

Sidebar

Related Questions

I am working on a small web dashboard -project that has backend implemented with
I'm working on a small project that involves me loading an image into a
i am working on a small project that i need the ability to let
I'm working on a small django project that will be deployed in a servlet
I have a small project that I will be working on shortly that collects
I'm working on a small Java project that now connects to a MS SQL
I'm working with a very small sample project that can be downloaded from here
I am working on a small project for learning PHP better. This project has
i'm working on a small project that is supposed to allow basic searches of
I'm working on a project which shall contain two targets. One for building a

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.