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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:20:25+00:00 2026-06-14T05:20:25+00:00

Hi I am pretty new to C++ I’m a lot more used to Java.

  • 0

Hi I am pretty new to C++ I’m a lot more used to Java. But what I want to do is create just an empty arrayList that can be used by all of my other functions.

In my .h file I created a new class which has 2 structs within it and about 6 methods. Each of these methods uses arrayLists of the struct objects, but I don’t want to have to pass in the arrayLists as parameters. What I am trying to do is similar to in Java when you create a field in a class.

The problem is when I declare the arrayList like this in my .h file…

structObject * myArrayList = new structObject[0];
int ARRAY_SIZE = arrayList.size;

I get a bunch of errors including new cannot be declared in a constant.

Where should I be trying to declare my empty arraylist?
Is this even permissible in 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-06-14T05:20:26+00:00Added an answer on June 14, 2026 at 5:20 am

    You are trying to put a definition in a header file. That is a not allowed. You can only put declarations in a header file.

    declaration in the header:

    structObject* myArrayList;
    #define ARRAY_SIZE 100
    

    definition in a source file:

    myArrayList = new structObject[ARRAY_SIZE];
    

    However, global variables are almost always a bad idea. I would find a way to pass the array as an argument to the necessary functions. You should also look into the Standard Template Library and look at different containers.

    one option:

    std::vector<structObject> myArrayList;
    

    That can be put in a header file, and the constructor will do necessary initialization.

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

Sidebar

Related Questions

Im pretty new to Java Web Services, but I cant find a good explanation
I am pretty new to PHP and MySQL and I just can't figure this
I'm pretty new to Eclipse plugins and I want to create a VerticalRuler, I
I'm pretty new to Android, I do know some Java though. I want to
Pretty new to Java and also to Mac ... I want to make sure
Pretty new to Java programming, but I'm having trouble getting this to run. I
Pretty new to drupal 7 and a lot has changed. How can I simply
I'm still pretty new to ObjC. I noticed that it's pretty standard everywhere to
I'm pretty new to PHP, but I decided to try and make a simple
Im pretty new to REST but as far as i have gathered i understand

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.