⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 动态创建二维数组??? c-c++ - c++ 语言 - 社区 community_csdn_net.htm

📁 很好的收集,看了以后都不知道说什么了. 都是关于内存调试方面的.十分有用.
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0050)http://www.80diy.com/home/20050215/16/3784196.html -->
<HTML lang=zh-CN xml:lang="zh-CN" 
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>动态创建二维数组??? C/C++ / C++ 语言 - 社区 community.csdn.net</TITLE>
<META content=all name=robots>
<META http-equiv=Content-Language content=zh-CN>
<META http-equiv=Content-Type content="text/html; charset=utf-8"><LINK 
href="动态创建二维数组??? C-C++ - C++ 语言 - 社区 community_csdn_net.files/topic.css" 
type=text/css rel=stylesheet>
<SCRIPT src="动态创建二维数组??? C-C++ - C++ 语言 - 社区 community_csdn_net.files/Topic.js" 
type=text/javascript></SCRIPT>

<META content=".net 指针 二维数组 ga 维数 resize 知道 C/C++ C++ 语言" name=Keywords>
<META content="int** p = new[3][3];为何错???" name=description>
<META content="MSHTML 6.00.2900.2096" name=GENERATOR></HEAD>
<BODY>
<SCRIPT language=javascript 
src="动态创建二维数组??? C-C++ - C++ 语言 - 社区 community_csdn_net.files/default_top_comm.js"></SCRIPT>

<SCRIPT language=javascript 
src="动态创建二维数组??? C-C++ - C++ 语言 - 社区 community_csdn_net.files/left_comm1.js"></SCRIPT>

<DIV id=wrapper>
<DIV id=innerWrapper>
<TABLE class=-PHF id=PHL cellSpacing=1 cellPadding=0 border=0>
  <TBODY>
  <TR>
    <TD><A href="http://www.csdn.net/" rel=external>首页</A></TD>
    <TD><A href="http://news.csdn.net/" rel=external>新闻</A></TD>
    <TD><A href="http://bbs.csdn.net/" rel=external><STRONG>论坛</STRONG></A></TD>
    <TD><A href="http://groups.csdn.net/" 
    rel=external><STRONG>小组</STRONG></A></TD>
    <TD><A href="http://blog.csdn.net/" 
    rel=external><STRONG>Blog</STRONG></A></TD>
    <TD><A href="http://dev.csdn.net/" rel=external>文档</A></TD>
    <TD><A href="http://download.csdn.net/" rel=external>下载</A></TD>
    <TD><A href="http://book.csdn.net/" rel=external>读书</A></TD>
    <TD><A href="http://tag.csdn.net/" 
rel=external><STRONG>Tag</STRONG></A></TD>
    <TD><A href="http://wz.csdn.net/" rel=external><STRONG>网摘</STRONG></A></TD>
    <TD><A href="http://search.csdn.net/" 
    rel=external><STRONG>搜索</STRONG></A></TD>
    <TD><A href="http://dotnet.csdn.net/" 
      rel=external><STRONG>.NET</STRONG></A></TD>
    <TD><A href="http://java.csdn.net/" 
    rel=external><STRONG>Java</STRONG></A></TD>
    <TD><A href="http://gamedev.csdn.net/" rel=external>游戏</A></TD>
    <TD><A href="http://live.csdn.net/" rel=external>视频</A></TD>
    <TD><A href="http://job.csdn.net/" rel=external>人才</A></TD>
    <TD><A href="http://prj.csdn.net/" rel=external>外包</A></TD>
    <TD><A href="http://www.dearbook.com.cn/" rel=external>第二书店</A></TD>
    <TD><A href="http://www.programmer.com.cn/" 
  rel=external>程序员</A></TD></TR></TBODY></TABLE>
<DIV id=logo><A href="http://www.80diy.com/bbs/" rel=external><IMG class=logo 
alt=社区 
src="动态创建二维数组??? C-C++ - C++ 语言 - 社区 community_csdn_net.files/logo_csdn.htm"></A><A 
href="http://book.csdn.net/" rel=external><IMG alt="" 
src="动态创建二维数组??? C-C++ - C++ 语言 - 社区 community_csdn_net.files/book_468_60.gif"></A><A 
href="http://search.codechina.net/" rel=external><IMG alt="" 
src="动态创建二维数组??? C-C++ - C++ 语言 - 社区 community_csdn_net.files/codesearch_120_60.gif"></A> 
<IMG style="DISPLAY: none" alt="" 
src="动态创建二维数组??? C-C++ - C++ 语言 - 社区 community_csdn_net.files/pv.htm"> </DIV>
<DIV id=navigation>
<DIV id=search>
<DIV id=innerSearch><INPUT id=key onfocus="value=''"><A 
onclick="return Search()" 
href="http://www.80diy.com/home/20050215/16/3784196.html#">搜索</A>&nbsp;|&nbsp;<A 
title=功能强大的网络收藏夹,一秒钟操作就可以轻松实现保存带来的价值、分享带来的快乐 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(saveit=window.open('http://wz.csdn.net/storeit.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'saveit','scrollbars=no,width=590,height=300,left=75,top=20,status=no,resizable=yes'));saveit.focus();">收藏</A>&nbsp;|&nbsp;<A 
onclick="return Print()" 
href="http://www.80diy.com/home/20050215/16/3784196.html#">打印</A>&nbsp;|&nbsp;<A 
onclick="return Close()" 
href="http://www.80diy.com/home/20050215/16/3784196.html#">关闭</A> </DIV></DIV>
<DIV><A class=Room href="http://www.80diy.com/bbs/" 
rel=external>社区</A>&nbsp;&gt;&nbsp; <A 
href="http://www.80diy.com/home/ForumsList.aspx?typenum=1&amp;roomid=56" 
rel=external>C/C++</A>&nbsp;&gt;&nbsp; <A 
href="http://www.80diy.com/home/ForumList.aspx?typenum=1&amp;roomid=5604" 
rel=external>C++ 语言</A> </DIV></DIV>
<DIV id=mainWrapper>
<DIV id=pageContent>
<DIV id=innerContent>
<H1>动态创建二维数组???</H1>
<DIV class=author><A class=anchor name=Top>楼主</A>samuellei(决不放弃)<INPUT class=user1 title="一级用户 该版得分小于等于100分" type=button>2005-02-15 
16:43:55 在 C/C++ / C++ 语言 提问</DIV>
<P>int** &nbsp; p &nbsp; = &nbsp; new[3][3]; &nbsp; <BR>&nbsp; 为何错??? 
<SPAN>问题点数:20、回复次数:6</SPAN><A 
href="http://www.80diy.com/home/20050215/16/3784196.html#">Top</A> </P>
<DIV class=tagad><IFRAME 
src="动态创建二维数组??? C-C++ - C++ 语言 - 社区 community_csdn_net.files/300.html" 
frameBorder=0 scrolling=no></IFRAME></DIV>
<H3><STRONG><A class=anchor name=r_27746667>1 楼</A>pcboyxhy(-273.15℃)<INPUT class=star2 title="二星用户 该版得分小于等于30000分,大于10000分" type=button></STRONG><SPAN>回复于 
2005-02-15 16:49:37 得分 <EM>5</EM></SPAN></H3>
<P>有有人问了 &nbsp; <BR>&nbsp; 怎么不查一下以前的帖? &nbsp; <BR>&nbsp; 
http://www.80diy.com/bbs/Expert/topic/3780/3780837.xml?temp=.7360803 &nbsp; 
<BR>&nbsp; &nbsp; <BR>&nbsp; 发信人: &nbsp; nichloas &nbsp; (nil), &nbsp; 信区: 
&nbsp; CPlusPlus &nbsp; <BR>&nbsp; 标 &nbsp; &nbsp; 题: &nbsp; [FAQ]二维数组new小结 
&nbsp; <BR>&nbsp; 发信站: &nbsp; BBS &nbsp; 水木清华站 &nbsp; &nbsp; <BR>&nbsp; (Sat 
&nbsp; Jun &nbsp; &nbsp; 7 &nbsp; 15:27:42 &nbsp; 2003), &nbsp; 转信 &nbsp; 
<BR>&nbsp; 1. &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; A &nbsp; (*ga)[n] 
&nbsp; = &nbsp; new &nbsp; A[m][n]; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
&nbsp; ... &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; delete &nbsp; []ga; 
&nbsp; <BR>&nbsp; 缺点:n必须是已知优点: &nbsp; <BR>&nbsp; 调用直观,连续储存,程序简洁(经过测试,析构函数能正确调用) 
&nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 2. &nbsp; &nbsp; <BR>&nbsp; &nbsp; A** 
&nbsp; ga &nbsp; = &nbsp; new &nbsp; A*[m]; &nbsp; &nbsp; &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; for(int &nbsp; i &nbsp; = &nbsp; 0; &nbsp; i &nbsp; &lt; 
&nbsp; m; &nbsp; i++) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; ga[i] &nbsp; = &nbsp; new &nbsp; A[n]; &nbsp; &nbsp; &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; ... &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; 
for(int &nbsp; i &nbsp; = &nbsp; 0; &nbsp; i &nbsp; &lt; &nbsp; m; &nbsp; i++) 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; delete 
&nbsp; []ga[i]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; delete &nbsp; 
[]ga; &nbsp; <BR>&nbsp; 缺点:非连续储存,程序烦琐, &nbsp; <BR>&nbsp; ga为A**类型优点:调用直观, &nbsp; 
<BR>&nbsp; n可以不是已知 &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 3. &nbsp; &nbsp; &nbsp; 
<BR>&nbsp; A* &nbsp; ga &nbsp; = &nbsp; new &nbsp; A[m*n]; &nbsp; &nbsp; &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; ... &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
delete &nbsp; []ga; &nbsp; <BR>&nbsp; 缺点:调用不够直观优点: &nbsp; <BR>&nbsp; 
连续储存,n可以不是已知 &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 4. &nbsp; &nbsp; &nbsp; 
<BR>&nbsp; vector&lt;vector&lt;A&gt; &nbsp; &gt; &nbsp; ga; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; <BR>&nbsp; ga.resize(m); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //这三行可用可不用 &nbsp; &nbsp; &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; for(int &nbsp; i &nbsp; = &nbsp; 1; &nbsp; i &nbsp; &lt; 
&nbsp; n; &nbsp; i++) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; // &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; 
&nbsp; &nbsp; ga[i].resize(n); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; &nbsp; 
&nbsp; &nbsp; ...缺点:非连续储存,调试不够方便,编译速度下降,程序膨胀(实际速度差别不大) &nbsp; <BR>&nbsp; 
优点:调用直观,自动析构与释放内存,可以调用stl相关函数,动态增长 &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 5. &nbsp; 
&nbsp; vector&lt;A&gt; &nbsp; ga; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; 
ga.resize(m*n); &nbsp; <BR>&nbsp; 方法3,4的结合 &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 
6. &nbsp; 2的改进版(Penrose提供,在此感谢) &nbsp; &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
A** &nbsp; ga &nbsp; = &nbsp; new &nbsp; A*[m]; &nbsp; &nbsp; &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; ga[0] &nbsp; = &nbsp; new &nbsp; A[m*n]; &nbsp; &nbsp; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; for(int &nbsp; i &nbsp; = &nbsp; 1; &nbsp; i &nbsp; 
&lt; &nbsp; m; &nbsp; i++) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <BR>&nbsp; &nbsp; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -