VC. STL Newsgroup Good Questions (2)
When Templated Member Function is used, the C2664 compilation error occurs. Why?
Article last modified on 2002-5-29
----------------------------------------------------------------
The information in this article applies:
-Microsoft Visual C ++, 32-bit Editions, version 6.0, SP5
----------------------------------------------------------------
Question:
The following code reports C2664 errors during compilation: 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 The Code is as follows: Istream_iterator IntFileBegin (); Istream_iterator IntFileEnd; List IntList (intFileBegin, intFileEnd ); |
Answer:
When the vc6 library file is released, the compiler does not support the templated member function. In this way, the templated list constructor cannot obtain non-list iterators. Although the compiler supports the templated member function, you still need a new standard library to compile the function. The previous code should be compiled in the following environment: N vc 7 N vc6 with dinkumware library upgrade N vc6 with stlport If you do not have such a compiling environment, do not useTemplated member function. You can do this: Istream_iterator Intfilebegin (CIN );
Istream_iterator Intfileend; List IntList; Copy (intfilebegin, intfileend, back_inserter (intlist )); In this way, you can import the items in istream to the list. |
(To be Continued)
Written by zhengyun@tomosoft.com
Trackback: http://tb.blog.csdn.net/TrackBack.aspx? PostId = 12674