VC.STL Newsgroup Good Questions(
二
)
使用
Templated Member Function
时
C2664
编译错误,
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> 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> intFileEnd;
list<int> intList;
copy(intFileBegin,intFileEnd,back_inserter(intList));
这样同样可以把
istream
中的东西导入到
list
中。
|
(To be Continued)
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=12674