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

  • Home
  • SEARCH
  • 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 8877997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:36:21+00:00 2026-06-14T19:36:21+00:00

Possible Duplicate: Using array as map value: Cant see the error Assume I have

  • 0

Possible Duplicate:
Using array as map value: Cant see the error

Assume I have the following data structure:

std::map<size_t, double[2] > trace;

how can I access its elements with the operator[]?

Essentially I want to do something like:

trace[0][0] = 10.0;
trace[0][1] = 11.0;

In compiling these lines of code I get the following error:

/usr/include/c++/4.6/bits/stl_map.h:453:11: error: conversion from ‘int’ to non-scalar type ‘std::map<long unsigned int, double [2]>::mapped_type {aka double [2]}’ requested

comments?

  • 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-14T19:36:23+00:00Added an answer on June 14, 2026 at 7:36 pm

    Value types for maps must be default-constructible, using an expression value_type(), in order to access them via []. For some mysterious reason, array types are not, as specified in C++11 5.3.2/2 (with my emphasis):

    The expression T(), where T is a simple-type-specifier or typename-specifier for a non-array complete object type … creates a prvalue of the specified type,which is value-initialized

    The compiler gives that strange error when trying to value-initialise an array; the following gives the same error:

    typedef double array[2];
    array();
    

    I suggest using a class type rather than double[2]: std::array<double,2>, std::pair<double,double>, or a struct containing two doubles. Such types are copyable, don’t decay into a pointer (losing compile-time knowledge of the size) at the drop of a hat, and are generally easier to deal than a built-in array type.

    If you’re stuck with an old library that doesn’t provide std::array, then you could use the very similar Boost.Array, or write your own simple class template to wrap an array.

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

Sidebar

Related Questions

Possible Duplicate: PHP get both array value and array key I am using Codeigniters'
Possible Duplicate: Using a bitwise & inside an if statement I have the following
Possible Duplicate: convert string to 2D array using php I have the string like
Possible Duplicate: MySQL query using an array Passing an array to mysql I have
Possible Duplicate: Mixed Array and object I'm using print_r to see what the array
Possible Duplicate: Can I call functions that take an array/pointer argument using a std::vector
Possible Duplicate: Using Perl, how can I sort an array using the value of
Possible Duplicate: Sorting NSString values as if NSInteger using NSSortDescriptor I have an Array
Possible Duplicate: PHP/MYSQL using an array in WHERE clause I have an array with
Possible Duplicate: Create an Array of the Last 30 Days Using PHP I am

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.