boost的多维数组的问题

gemo 2010-01-07 02:14:33
我想在程序中使用一个动态二维数组 于是依据boost::multi_array封装了如下类
大家帮忙看看这个封装有没有问题?
因为现在我在VS2008中build的时候会出现一些莫名其妙链接错误(cannot open file xx.exe for write),最要命的是还不是必现!有时候可以正常build!我怀疑是MSVC的一些内部问题但报的错误并不对(绝对不是进程没有退出导致无法覆盖的问题 我重新开机之后直接编译也会报这个错)

但是将这个类的使用完全注释掉之后就肯定build成功!

麻烦大家帮我看看 多谢



#include <boost/multi_array.hpp>

template<typename T>
class RectArray
{
typedef boost::multi_array<T,2> RA_TYPE;

public:
RectArray() { Resize(0, 0); }
RectArray(int width, int height) { Resize(width, height); }

T* operator[](int i) { return &(m_ra[i][0]); }

void Resize(int width, int height) { m_ra.resize(boost::extents[height][width]); }

int GetWidth() { return m_ra.shape()[1]; }

int GetHeight() { return m_ra.shape()[0]; }

private:
RA_TYPE m_ra;
};
...全文
259 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Pepeet 2010-01-09
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 brainstorm_lee 的回复:]
结贴吧~
[/Quote]
Raul_Gonzalez 2010-01-09
  • 打赏
  • 举报
回复
结贴吧~
mLee79 2010-01-07
  • 打赏
  • 举报
回复
程序员嘛,还是裸奔的好,自从关闭自动更新/防火墙, 卸掉杀毒软件后, 再也没有出过什么莫名其妙的问题...

ImJaden 2010-01-07
  • 打赏
  • 举报
回复
呵呵,原来如此!
gemo 2010-01-07
  • 打赏
  • 举报
回复
卧草NOD32祖宗
gemo 2010-01-07
  • 打赏
  • 举报
回复
卧草泥马 原来是NOD32这B捣的鬼
masterz 2010-01-07
  • 打赏
  • 举报
回复
是不是数组越界了?
#include <boost/multi_array.hpp>
#include <iostream>
template <typename T>
class RectArray
{
typedef boost::multi_array <T,2> RA_TYPE;
typedef boost::multi_array_ref<T, 1> RA_TYPE1;
public:
RectArray() { Resize(0,0); }
RectArray(int width, int height)
{ Resize(width, height); }
T* operator[](int i) { return &(m_ra[i][0]); }
void Resize(int width, int height)
{
m_ra.resize(boost::extents[height][width]);
RA_TYPE1 a_ref(m_ra.data(), boost::extents[m_ra.num_elements()]);
std::fill(a_ref.begin(), a_ref.end(), 1);
}
int GetWidth() { return m_ra.shape()[1]; }
int GetHeight() { return m_ra.shape()[0]; }
private:
RA_TYPE m_ra;
};

int main()
{
RectArray<int> nra;
nra.Resize(4, 3);
nra[0][0] = __LINE__;
nra[2][3] = __LINE__;
for (int i=0; i<nra.GetHeight();i++)
{
for (int j=0; j<nra.GetWidth(); j++)
std::cout << nra[i][j] << " ";
std::cout << std::endl;
}

return 0;
}

/*
cl /EHsc /ID:\opensource\boost_1_40_0 /MD marray.cpp /link /VERBOSE:LIB /LIBPATH:"D:\opensource\boost\boost_1_40_0\stage\lib"

*/
taodm 2010-01-07
  • 打赏
  • 举报
回复
呃,不如还是就用vector<vector >吧。

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧