简体   繁体   中英

error is xmemory - c++0x support missing?

I have made a winform app where i have used vectors of array[n][n] type using

typedef char myarray[9][9];  
typedef vector<myarray> array3d; 

as far as i have read, this feature is provided in c++0x. I am using visual studio 2010 ultimate is the error in xmemory because of this? The ide is showing no other error exept from this (not even where the above code is)

'Target of operator new()' : array initialization needs curly braces

pointing to this code in xmemory

void construct(pointer _Ptr, _Ty&& _Val)
    {   // construct object at _Ptr with value _Val
    ::new ((void _FARQ *)_Ptr) _Ty(_STD forward<_Ty>(_Val));
    }

In a code of over 2.5 k lines how do i find where's the problem?

EDIT:

Since the problems seem with vectors here are all the operations that i do with vectors

#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef char myarray[9][9];
typedef string string_array[9][9];

void function2(vector<string_array>*my_3d_string_array, int d)
{
    string::iterator it;
    int j,cl;
    it=find((*my_3d_string_array)[d][j][cl].begin(),(*my_3d_string_array)[d][j][cl].end(),3);
    (*my_3d_string_array)[d][2][3].erase(it);
}

void function(vector<string_array>*my_3d_string_array, int d)
{
    (*my_3d_string_array)[d][3][4] = 2;
    function2(my_3d_string_array,d);
}

int main()
{
    myarray matrix;
    string_array string_matrix;

    std::vector<myarray>      my_3d_array;
    std::vector<string_array> my_3d_string_array;

    // fill_matrix(matrix);
    // fill_string_matrix(string_matrix)

    int d;
    function(&my_3d_string_array, d); // passing pointer to vector to a function d is the 3rd dimention

    my_3d_array.push_back(matrix);
    my_3d_string_array.push_back(string_matrix);
}

is there a stupid error i am making here?

Array types are not supported as the elements in containers.

The workaround is, probably, to use std::array<> instead of char[]

#include <vector>
#include <array>

typedef std::array<std::array<char,4>, 6> array;
typedef std::vector<array> _3darray; 

int main()
{
    _3darray a, b;
    a = b;
}
  • g++ 4.6 likes it
  • MSVC++ 2010 doesn't likes it too :)

Because template types are instantiated at compile time, it is not possible to have a runtime variable participate (even indirectly) in a template argument, even with C++0x.

You may be interested in the boost multidimensional array library , however, which can be used to declare 3d arrays easily. Here's an example from the docs:

#include "boost/multi_array.hpp"
#include <cassert>

int 
main () {
  // Create a 3D array that is 3 x 4 x 2
  typedef boost::multi_array<double, 3> array_type;
  typedef array_type::index index;
  array_type A(boost::extents[3][4][2]);

  // Assign values to the elements
  int values = 0;
  for(index i = 0; i != 3; ++i) 
    for(index j = 0; j != 4; ++j)
      for(index k = 0; k != 2; ++k)
        A[i][j][k] = values++;

  // Verify values
  int verify = 0;
  for(index i = 0; i != 3; ++i) 
    for(index j = 0; j != 4; ++j)
      for(index k = 0; k != 2; ++k)
        assert(A[i][j][k] == verify++);

  return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM