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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:57:31+00:00 2026-06-19T01:57:31+00:00

If I manually type this script and call the calculator : integer array[100]; Then

  • 0

If I manually type this script and call the calculator :

integer array[100];

Then my calculator will create a vector<int> object with the name “array” contains 100 elements.

But C++ code is unique. For example if I type and call :

integer array[100][100];
integer array[100][100][100];
//etc

Then the template vector<int> is illegal…. 🙁

So annoying! I tried but I could not find the better solution. Could anyone give me some hint?

  • 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-19T01:57:33+00:00Added an answer on June 19, 2026 at 1:57 am

    This answer covers to generally different approaches.


    To support arbitrarily nested, dynamically sized arrays (so the depth of the nested arrays is not limited during compile time), you should use something like the following.

    The type of a variable in your scripting language should be either:

    • integer
    • float
    • (… other primitive types you want to support …)
    • an array of any of these types (including array)
    • (… other container types such as an associative map if you want to support it …)

    This is typically done using a “variant” type, such as Boost Variant or QVariant in Qt. A variant type is basically a union of a set of types (so it is one of them) plus a type descriptor which tells which type it actually contains.

    So an array of any type can be represented, also if this “any type” is an array again. So you can support a dynamic depth of nested arrays.

    Note that the “array of any types” should actually be a vector of this variant type. The problem with Boost Variant is that you have to explicitly list the types it can hold as template arguments. This will result in a recursion:

    boost::variant<int, float, ..., std::vector<boost::variant<..., ...> > >
                                                ^^^^^^^^^^^^^^^^^^^^^^^^
                                                        recursion
    

    In Qt there is the type QVariant which can hold basically any type supported by Qt. QVariant is not a template class and thus its type doesn’t contain such a recursion. I don’t know if there is a comparable boost type, but I doubt it.


    If your arrays can’t be resized during execution of the script (or if they should be resized, you can allocate a new one and copy the contents), there is a simpler solution. Just store the arrays in a one-dimensional vector, also store the dimensions of the array in your scripting language in another vector. Then you can use an index method like the following.

    class ScriptArray {
        vector<int> dim;
        vector<int> elements;
    
        int getIndex(vector<int> indexList) const {
            int multiplicator = 1;
            int index = 0;
            for (int i = 0; i < dim.size(); ++i) {
                index = multiplicator * indexList[i];
                multiplicator *= dim[i];
            }
            return index;
        }
    };
    

    This is basically a generalization of the following idea. Consider a two-dimensional array (100 x 100 elements) you want to represent as a one-dimensional one (10000 elements). For any index in the original array (x, y) you can map this to a one-dimensional index for your internal array (x + 100 * y). For a three-dimensional array this just contains another multiplication (x + 100 * y + 100*100 * z) and so on…

    The problem with this solution and resizing the array is that the elements “move” within the array when the size of a dimension changes (special case: last dimension, as this dimension is the “outermost” one). So either you can live with the fact that the array would be invalid when resized, or you copy the contents in a new array with the new size, or you implement some complicated resize method which carefully inserts spaces / removes some elements in the array at the correct places.

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

Sidebar

Related Questions

Are there any circumstances where it is favourable to manually create a stub type,
How do I disable UAC using a PowerShell script? I can do this manually
I'm having an issue getting this jQuery.ajax call to work. When the script executes
I have a script that manually preloads all images that will be required. It
I'm trying to use this function for infinite scroll: <script type=text/javascript charset=utf-8> (function() {
I can connect manually by doing: M-x sql-postgres and type the User, Database, Host,
I want to manually create a ID field where I do MAX + 1,
I can create database manually by going to cpanel. But I'd like to create
I would like to write a script that will tell another server to SVN
SUMMARIZE: I misunderstood the usage of content script. And that leads to this issue.

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.