2D指针数组,全部设为null? [英] 2D-array of pointers, set all to null?
问题描述
您好,c ++标准库中是否有一些可以帮助的东西?b $ b我将二维指针数组的所有元素都设置为NULL?喜欢
fill_n(),也许吧?现在,我正在使用两个for循环(一个嵌套)和
想知道有哪些替代品。我的编译器带有一个
初步的TR1实现。
我需要做的另一件事就是在
数组中的指针上调用delete在程序的其他一点上,我是否坚持使用两个用于
循环?
- Eric
WP写道:
您好,c ++标准库中有什么东西可以帮助
我将二维指针数组的所有元素都设置为NULL?喜欢
fill_n(),也许吧?现在,我正在使用两个for循环(一个嵌套)和
想知道有哪些替代品。我的编译器带有一个
初步的TR1实现。
我需要做的另一件事就是在
数组中的指针上调用delete在程序中的其他一点,我是否坚持使用这两个用于
循环?
嗯,你可以用一个memset()调用来做,但我不是
绝对确定它是多么便携(虽然我相信它是便携的
*在练习中*)。
On 2008-07-12 06:28:49 - 0400,WP< in ***** @ invalid.invalidsaid:
您好,c ++标准库中有什么东西可以
帮我设置二维指针数组的所有元素到
NULL?像fill_n(),也许?现在,我正在使用两个for循环(一个
嵌套),并想知道有什么替代品。我的编译器
附带初步的TR1实现。
我需要做的另一件事就是在
数组中的指针上调用delete在程序的其他一点,我是否坚持使用两个用于
循环?
两个循环有什么问题?这符合数据结构。
-
Pete
Roundhouse Consulting,Ltd。( www.versatilecoding.com )作者
标准C ++库扩展:一个教程和参考
( www.petebecker.com/tr1book )
7月12日下午12:53,Juha Nieminen< nos ... @ thanks.invalidwrote:
WP写道:
您好,c ++标准库中有什么东西
可以帮我设置二维数组的所有元素
指向NULL的指针?像fill_n(),也许?现在,我是
使用两个for循环(一个嵌套)并且想知道什么是
替代品。我的编译器带有一个初步的
TR1实现。
我需要做的另一件事就是在指针上调用delete
在数组中在程序中的其他一点上,我是否因为两个for循环而停留了
?
嗯,你可以用一个memset()调用来做,但我不是
绝对确定这是多么便携(虽然我相信它是实时的* b $ b便携式*)。
你不能用memset设置指向null的指针。在实践中它不是便携式的(实际上是可行的(虽然它适用于一些广泛使用的
系统)。
-
James Kanze(GABI软件)电子邮件:ja ********* @ gmail.com
Conseils eninformatiqueorientéeobjet/
Beratung in objektorientierter Datenverarbeitung
9placeSémard,78210 St.-Cyr-l''coco,France,+ 33(0)1 30 23 00 34
Hello, is there something neat in the c++ standard library that can help
me set all elements of a two-dimensional array of pointers to NULL? Like
fill_n(), maybe? Right now, I''m using two for loops (one nested) and
wanted to know what alternatives there are. My compiler ships with a
preliminary TR1-implementation.
Another thing I need to do is to call delete on the pointers in the
array at some other point in the program, am I stuck with the two for
loops there?
- Eric
WP wrote:Hello, is there something neat in the c++ standard library that can help
me set all elements of a two-dimensional array of pointers to NULL? Like
fill_n(), maybe? Right now, I''m using two for loops (one nested) and
wanted to know what alternatives there are. My compiler ships with a
preliminary TR1-implementation.
Another thing I need to do is to call delete on the pointers in the
array at some other point in the program, am I stuck with the two for
loops there?Well, you could do it with a single memset() call, but I''m not
absolutely sure how portable that is (although I believe it''s portable
*in practice*).
On 2008-07-12 06:28:49 -0400, WP <in*****@invalid.invalidsaid:
Hello, is there something neat in the c++ standard library that can
help me set all elements of a two-dimensional array of pointers to
NULL? Like fill_n(), maybe? Right now, I''m using two for loops (one
nested) and wanted to know what alternatives there are. My compiler
ships with a preliminary TR1-implementation.
Another thing I need to do is to call delete on the pointers in the
array at some other point in the program, am I stuck with the two for
loops there?
What''s wrong with two loops? That matches the data structure.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
On Jul 12, 12:53 pm, Juha Nieminen <nos...@thanks.invalidwrote:WP wrote:Hello, is there something neat in the c++ standard library
that can help me set all elements of a two-dimensional array
of pointers to NULL? Like fill_n(), maybe? Right now, I''m
using two for loops (one nested) and wanted to know what
alternatives there are. My compiler ships with a preliminary
TR1-implementation.
Another thing I need to do is to call delete on the pointers
in the array at some other point in the program, am I stuck
with the two for loops there?
Well, you could do it with a single memset() call, but I''m not
absolutely sure how portable that is (although I believe it''s
portable *in practice*).You can''t set pointers to null with memset. And it''s not
portable in practice (although it will work on a few widely used
systems).
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l''école, France, +33 (0)1 30 23 00 34
这篇关于2D指针数组,全部设为null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!