Sign in to follow this  
lord4n

2D Arrays in C++

Recommended Posts

std::vector< std::vector<int> >
fro a 2d array

this creates a vector of vectors so for 3d u just say

std::vector< std::vector< std::vector<int> > >
and so on for more dimensions.

hope that helps

Share this post


Link to post
Share on other sites
The difficulty with vectors (and dynamic C "arrays") is that they are potentially ragged. The tool of choice for representing matrices is not a vector of vectors (its semantics are no better than those of C arrays), but boost::multi_array.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
The difficulty with vectors (and dynamic C "arrays") is that they are potentially ragged. The tool of choice for representing matrices is not a vector of vectors (its semantics are no better than those of C arrays), but boost::multi_array.


I have heard about those boost libraries but they're not part of the C++
Syntax so i should download them anyway?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Many of the boost libraries have become part of the c++ technical release, they are made by C++ experts to create well thought extra libraries and most PC based developers consider boost as good as a official C++ library.

That being said, they can be bloated for console development (like PS2, XBox) etc, and generally in those circumstances you want to do testing to see which parts of boost you can and can't use, but this probably doesn't effect many people here but worth a mention (we at work use current gen and next gen consoles and tend to use boost but only specific libraries that have turned up alright performance in testing)

Share this post


Link to post
Share on other sites
okay, i download the boost libraries and i was trying to use it, but im have some problems..

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

using namespace std;

int main(int argc, char** argv)
{
typedef boost::multi_array<double, 3> array_type;

array_type A(boost::extents[3][4][2]);
boost::array<array_type::index,3> idx = {{0,0,0}};

A(idx) = 3.14;
assert(A(idx) == 3.14);

return 0;
}




it should work good i only copied the code from:
http://www.boost.org/libs/multi_array/doc/user.html#sec_access

it works ok, but im getting those weird errors:
http://rafb.net/paste/results/tAJjry16.html ().

how can i get rid of them ?

Share this post


Link to post
Share on other sites
You are getting warnings about uses of the boost library. You can disable them by wrapping their inclusion with #pragma pop, push and warning preprocessor statements. See the documentation of your compiler about these statements and how to use them.

Share this post


Link to post
Share on other sites
Quote:
From msdn:
#pragma warning( push )
#pragma warning( disable : 4705 )
#pragma warning( disable : 4706 )
#pragma warning( disable : 4707 )
// Some code
#pragma warning( pop )


If you replace // some code by the inclusion of the boost headers, the warnings will be suppressed for these headers alone.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this