VS 2005应该允许这个,为什么? [英] VS 2005 should allows this, why?

查看:72
本文介绍了VS 2005应该允许这个,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< set>


using namespace std;


int main()

{


typedef set< intINTSET;


INTSET coll;


INTSET :: iterator pos = coll.begin();


* pos = 9; // VS 2005应该允许这个,为什么?


}


集合将包含两个相同的值,它违反了一套规则

最多包含每个键值之一。

解决方案

Lighter写道:
< blockquote class =post_quotes>
#include< set>

using namespace std;


int main()< br $>
{


typedef set< intINTSET;



所有上限通常用于宏。


INTSET coll;


INTSET :: iterator pos = coll.begin();


* pos = 9; // VS 2005应该允许这个,为什么?



为什么要特别推出VS 2005?


-

Ian Collins。


Lighter写道:


#include< set> ;


使用命名空间std;


int main()

{


typedef set< intINTSET;


INTSET coll;


INTSET :: iterator pos = coll.begin();


* pos = 9; // VS 2005应该允许这个,为什么?



没有C ++编译器会允许这样做。


上面的语句pos具有值为

的coll.end()。你不能取消引用它。


我认为你有迭代器和插入器的概念

困惑。


Lighter写道:


#include< set>


using namespace std;


int main()

{


typedef set< intINTSET;


INTSET coll;


INTSET :: iterator pos = coll.begin();


* pos = 9; // VS 2005应该允许这个,为什么?



此时,你有未定义的行为,任何事情都可能发生。


}


#include <set>

using namespace std;

int main()
{

typedef set<intINTSET;

INTSET coll;

INTSET::iterator pos = coll.begin();

*pos = 9; // VS 2005 should allowes this, why?

}

the set will contain two same values, it violates the rule that a set
at most contains one of each key value.

解决方案

Lighter wrote:

#include <set>

using namespace std;

int main()
{

typedef set<intINTSET;

All caps is usually used form macros.

INTSET coll;

INTSET::iterator pos = coll.begin();

*pos = 9; // VS 2005 should allowes this, why?

Why should it and why VS 2005 in particular?

--
Ian Collins.


Lighter wrote:

#include <set>

using namespace std;

int main()
{

typedef set<intINTSET;

INTSET coll;

INTSET::iterator pos = coll.begin();

*pos = 9; // VS 2005 should allowes this, why?

No C++ compiler will allow this.

At the point of the above statement pos has the value
of coll.end(). You can''t dereference it.

I think you have the concept of iterators and inserters
confused.


Lighter wrote:

#include <set>

using namespace std;

int main()
{

typedef set<intINTSET;

INTSET coll;

INTSET::iterator pos = coll.begin();

*pos = 9; // VS 2005 should allowes this, why?

At this point, you have undefined behavior, and ANYTHING can happen.

}


这篇关于VS 2005应该允许这个,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆