null或nil或初始化的std :: list iterator? [英] null or nil or initialised std::list iterator?
问题描述
我想知道如何设置std :: list迭代器变量使其成为
null或nil。如果这不可能,那么
未初始化的std :: list迭代器的值是否可以将此值赋给
std :: list迭代器变量(或者更好的是使用单独的bool
变量作为空标志?)
例如
struct mystru
{
std :: string nm;
int qty;
}
>
std :: list< mystru> :: iterator i;
//我的价值是多少?
....
i = somelist.begin();
//用我做的事情
....
i = NULL_VALUE?
sa ************ @ hotmail.com 写道:我想知道如何设置std :: list iterator变量使它成为null或nil。如果这不可能,那么
未初始化的std :: list迭代器的值是否可以将此值赋给
std :: list iterator变量(或者更好地使用单独的bool
变量为null flag?)
struct mystru
{
std :: string nm;
int数量;
}
std :: list< mystru> :: iterator i;
//我的价值是多少?
未指定。你不能使用我而不给它一个值
...
我= somelist.begin();
//用我做的事情
。 ..
i = NULL_VALUE?
i = somelist.end(); //容器的结束迭代器是一个过了容器的
结尾
Alipha写道:
未指定。 $不能给它一个价值
我认为这就是重点,我想知道它什么时候没有价值
有一个值还是算数呢?
iterator怎么样(NULL)?
sa************@hotmail.com 写道:
未指定。你不能使用我而不给它一个价值
我认为这就是重点,我想知道什么时候它没有价值或者算不上使用它呢?
iterator(NULL)怎么样?
使用指向迭代器的指针,将其设置为0表示缺席。
迭代器没有空状态。
Marc
I want to know how to set an std::list iterator variable to make it
null or nil. If this is not possible what is the value of an
uninitialised std::list iterator and is it ok to assign this value to a
std::list iterator variable (or is it better to use a seperate bool
variable as a "null flag" ?)
e.g.
struct mystru
{
std::string nm;
int qty;
}
std::list<mystru>::iterator i;
// what is the value of i ?
....
i = somelist.begin();
// do things with i
....
i = NULL_VALUE?
解决方案
sa************@hotmail.com wrote:I want to know how to set an std::list iterator variable to make it
null or nil. If this is not possible what is the value of an
uninitialised std::list iterator and is it ok to assign this value to a
std::list iterator variable (or is it better to use a seperate bool
variable as a "null flag" ?)
e.g.
struct mystru
{
std::string nm;
int qty;
}
std::list<mystru>::iterator i;
// what is the value of i ?
unspecified. you CAN''T use i without giving it a value
...
i = somelist.begin();
// do things with i
...
i = NULL_VALUE?
i = somelist.end(); // the end iterator of a container is one-past the
end of the container
Alipha wrote:
unspecified. you CAN''T use i without giving it a value
I think that is the point, I want to know when it does not
have a value or does that count as using it too?
what about iterator(NULL) ?
sa************@hotmail.com wrote:
unspecified. you CAN''T use i without giving it a value
I think that is the point, I want to know when it does
not have a value or does that count as using it too?
what about iterator(NULL) ?
Use a pointer to iterator, set it to 0 to signal absence.
iterators don''t have a Null State.
Marc
这篇关于null或nil或初始化的std :: list iterator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!