Boost::multi_array使用【待更新】
http://wybolf.spaces.live.com/blog/cns!dbb6bcadeeb5ae52!170.entry
#pragma warning(disable:4996)//取出boost下的警告
#include <boost/multi_array.hpp>
#include <string>
#include <iostream>
using namespace std;
class Test
{
public:
Test();
~Test();
void SetMulti(int , int );
void PrintMulti(int, int );
private:
typedef boost::multi_array<int, 2> array_type;
array_type *m_pTestMulti;
};
Test::Test()
{
m_pTestMulti = NULL;
}
Test::~Test()
{
if(m_pTestMulti != NULL)
{
delete m_pTestMulti;
m_pTestMulti = NULL;
}
}
void Test::SetMulti(int rows, int cols)
{
m_pTestMulti = new array_type(boost::extents[rows][cols]);
for(int i = 0; i < rows; ++ i)
{
for(int j = 0; j < cols; ++ j)
{
(*m_pTestMulti)[i][j] = i * j;
}
}
}
void Test::PrintMulti(int rows, int cols)
{
if(m_pTestMulti != NULL)
{
for(int i = 0; i < rows; ++ i)
{
for(int j = 0; j < cols; ++ j)
{
cout << (*m_pTestMulti)[i][j] << " ";
}
cout << endl;
}
}
}
浙公网安备 33010602011771号