VC语言

本类阅读TOP10

·VC++ 学习笔记(二)
·用Visual C++打造IE浏览器(1)
·每个开发人员现在应该下载的十种必备工具
·教你用VC6做QQ对对碰外挂程序
·Netmsg 局域网聊天程序
·Windows消息大全
·VC++下使用ADO编写数据库程序
·VC++学习笔记(四)
·非法探取密码的原理及其防范
·怎样在VC++中访问、修改注册表

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
VC.STL Newsgroup Good Questions(二)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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<int,class std::allocator<int> >::std::list<int,class std::allocator<int> >(unsigned int,const int &,const class std::allocator<int> &)' : cannot convert parameter 1 from 'class std::istream_iterator<int,char,struct std::char_traits<char> > (__cdecl *)(void)' to 'unsigned int'        This conversion requires a reinterpret_cast, a C-style cast or function-style cast

代码如下:
istream_iterator<int> intFileBegin();

istream_iterator<int> intFileEnd;

list<int> 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<int> intFileBegin(cin);

istream_iterator<int> intFileEnd;

list<int> intList;

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

 

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

 

(To be Continued)

 

Written by [email protected]


相关文章

相关软件