VC.STL Newsgroup Good Questions(二)

VC.STL Newsgroup Good Questions()

    使用Templated Member FunctionC2664编译错误,Why?

Article last modified on 2002-5-29

----------------------------------------------------------------

The information in this article applies to:

-        Microsoft Visual C++, 32-bit Editions, version 6.0, SP5

----------------------------------------------------------------

 

Question:

下面的代码编译时报告C2664错误:

Error C2664: '__thiscall std::list >::std::list >(unsigned int,const int &,const class std::allocator &)' : cannot convert parameter 1 from 'class std::istream_iterator > (__cdecl *)(void)' to 'unsigned int'         This conversion requires a reinterpret_cast, a C-style cast or function-style cast

代码如下:
istream_iterator intFileBegin();

istream_iterator intFileEnd;

list intList(intFileBegin, intFileEnd);

 

Answer:

VC6的库文件刚发布的时候,编译器还不支持Templated Member Function。这样,Templated List Constructor无法得到Non-List Iterators

现在编译器虽然支持Templated Member Function,但要想编译通过,你还是需要一个新的标准库。前面的代码应该在以下环境中可以编译通过:

n        VC 7

n        VC6 with Dinkumware library upgrade

n        VC6 with STLport

 

如果你没有这样的编译环境,那还是不要使用Templated Member Function。你可以这么做:


istream_iterator intFileBegin(cin);

istream_iterator intFileEnd;

list intList;

copy(intFileBegin,intFileEnd,back_inserter(intList));

 

这样同样可以把istream中的东西导入到list中。

 

(To be Continued)

 

Written by zhengyun@tomosoft.com

Trackback: http://tb.blog.youkuaiyun.com/TrackBack.aspx?PostId=12674


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值