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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:46:03+00:00 2026-06-18T00:46:03+00:00

I have a project using cocos2d-x library that contains a lot of classes. I

  • 0

I have a project using cocos2d-x library that contains a lot of classes. I have a .h file contains a global vector. I want to initialize it when the program starts in an intro page class. Intro page class has a graphical surface and a loader. Then I want to use that vector in my main class. The global vector’s code is like bellow:

//globals.h
#ifndef _GLOBAL_H
#define _GLOBAL_H
#include <vector>

vector<int> a;
#endif

I am using push_back in intro page class. I have used extern and static keywords. my program makes a runtime linker error and it say your vector have been declared in appDelegate class (base class of cocos2d). when I put a static keyword behind it, it don’t give me that linker error but it don’t work correctly.
how can I correct this error? if you have another idea instead of this one, please share it. thank you.

  • 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-18T00:46:04+00:00Added an answer on June 18, 2026 at 12:46 am

    You should have a design like the following:

    shared.cpp

    vector<int> a;
    

    shared.h

    extern vector<int> a;
    

    somewhere.cpp

    #include "shared.h"
    void code() {
      a.push_back(10);
    }
    

    Mind that, since you are using C++, you can uses classes as namespaces to avoid cluttering the global namespace, eg:

    shared.cpp

    vector<int> Common::a;
    

    shared.h

    class Common {
      public:
        static vector<int> a;
    }
    

    somewhere.cpp

    #include "shared.h"
    void code() {
      Common::a.push_back(10);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully implemented slider to my Cocos2D project using this resource . The
I have a project that using some third-party libraries. My questions is how to
I have a lein project (using cascalog--but that's not particularly important). I'm trying to
I have a project containing cocos2d framework, sharekit, asi & json. I've noticed that
In my cocos2d project, I have two scenes. I transition between the two using
I am using a UISwitch in my cocos2d project like so: //header file UISwitch
Summary : I have a project using GNU Autotools. I have a pot file.
I have a project using log4j. Now I have to introduce a library using
I have a project using curses and sockets to make a talking program. Basically
I have my project using MVC and I've got my controller that instantiates 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.