how to avoid array subscript problem, unknown size

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nevetta
    New Member
    • Jan 2013
    • 1

    how to avoid array subscript problem, unknown size

    Code:
    cout<< "Insert the maximum number of hops of the routing algorithm used  :";
      cin>> num_of_hops;
      cout << endl << "number of paths : " << num_of_paths << endl;
    int path_matrix[][];
     path_matrix[num_of_paths][num_of_hops + 1];
    float path_length[];  // The total length of each path
     path_length[num_of_paths];
    error C2057: expected constant expression
    error C2466: cannot allocate an array of constant size 0
    error C2133: 'a' : unknown size
    error C2057: expected constant expression
    error C2466: cannot allocate an array of constant size 0
    Last edited by Rabbit; Jan 29 '13, 04:23 PM. Reason: Please use code tags when posting code.
  • Anas Mosaad
    New Member
    • Jan 2013
    • 185

    #2
    Why don't you use pointers instead? I'm not sure if there's away to define a static array dimensions at runtime in C++ -at least I don't know how.

    Alternatively, you may use vector http://www.cplusplus.com/reference/v...vector/vector/

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      Could you create the array dynamically at run time using new and delete?

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Read this: http://bytes.com/topic/c/insights/77...rrays-revealed.

        You are not following some of the rules for arrays.

        Comment

        Working...