473,322 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Wrong vector ctor used with iterator

I have this iterator:

class CFileIterator : public std::iterator<std::input_iterator_tag,
const std::wstring>
{
public:
CFileIterator(const std::wstring& wildcardPath);
....
};

which I instantiate like this:

CFileIterator it(SomePathWithWildcard), end;

I was hoping to be able to fill a vector using the iterator, like this:

std::vector<std::wstring> filenames(it, end);

but the compiler spits this into my face:

error C2664:
'std::vector<_Ty>::vector(std::vector<_Ty>::size_t ype,
const _Ty &,const _A &)'
: cannot convert parameter 1 from 'CFileIterator'
to 'std::vector<_Ty>::size_type'

Apparently, the compiler believes I want to call the vector ctor

vector(size_type, const Type&, const Allocator&);

instead of

template<class InputIterator>
vector(InputIterator, InputIterator, const Allocator&);

I use the aged and all but standards compliant Dinkumware STL bundled
with Platform Builder 5 - it's probably the same that shipped with old
Visual C++ 6.
Any ideas what I might try to get resolve the ctor call correctly?

Jul 22 '05 #1
5 2393
Johann Gerell wrote:
[...]
I use the aged and all but standards compliant Dinkumware STL bundled
with Platform Builder 5 - it's probably the same that shipped with old
Visual C++ 6.
Any ideas what I might try to get resolve the ctor call correctly?


You might want to think of chaining the library implementation or updating
the compiler... Otherwise, compiler-specific questions should go to the
compiler-specific newsgroups (microsoft.public.vc.language, in your case).

VC++ v6 fails to compile this simple code with the same error message:

#include <vector>

int main()
{
std::vector<int> vi;
std::vector<double> vd(vi.begin(), vi.end());
}

Its template handling is seriously screwed up.

V
Jul 22 '05 #2
Victor Bazarov wrote:
Johann Gerell wrote:
[...]
I use the aged and all but standards compliant Dinkumware STL bundled
with Platform Builder 5 - it's probably the same that shipped with old
Visual C++ 6.
Any ideas what I might try to get resolve the ctor call correctly?

You might want to think of chaining the library implementation or updating
the compiler... Otherwise, compiler-specific questions should go to the
compiler-specific newsgroups (microsoft.public.vc.language, in your case).

VC++ v6 fails to compile this simple code with the same error message:

#include <vector>

int main()
{
std::vector<int> vi;
std::vector<double> vd(vi.begin(), vi.end());
}

Its template handling is seriously screwed up.


Well, that may be, but that's not really the cause of the error message.
<g> The problem is that the library doesn't define a constructor that
takes two arguments of an arbitrary iterator type; it only defines one
that takes vector::iterator. That's because of a limitation in early
versions of VC6. With SP6 (or is it 5?) that limitation is no longer
present. You can edit the header and change

typedef const_iterator _It;
vector(_It _F, _It _L, const _A& _Al = _A())
: allocator(_Al), _First(0), _Last(0), _End(0)
{insert(begin(), _F, _L); }

to

typedef const_iterator _It;
template <class _It>
vector(_It _F, _It _L, const _A& _Al = _A())
: allocator(_Al), _First(0), _Last(0), _End(0)
{insert(begin(), _F, _L); }

Or you can remove the typedef completely and add 'template <class _It>'
in front of each member function that takes a pair of arguments of type
_It. That's a better fix, but it's a little bigger.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #3
Pete Becker wrote:
Victor Bazarov wrote:
Johann Gerell wrote:
[...]
I use the aged and all but standards compliant Dinkumware STL bundled
with Platform Builder 5 - it's probably the same that shipped with old
Visual C++ 6.
Any ideas what I might try to get resolve the ctor call correctly?


You might want to think of chaining the library implementation or
updating
the compiler... Otherwise, compiler-specific questions should go to the
compiler-specific newsgroups (microsoft.public.vc.language, in your
case).

VC++ v6 fails to compile this simple code with the same error message:

#include <vector>

int main()
{
std::vector<int> vi;
std::vector<double> vd(vi.begin(), vi.end());
}

Its template handling is seriously screwed up.


Well, that may be, but that's not really the cause of the error message.
<g> The problem is that the library doesn't define a constructor that
takes two arguments of an arbitrary iterator type; it only defines one
that takes vector::iterator. That's because of a limitation in early
versions of VC6. With SP6 (or is it 5?) that limitation is no longer
present. You can edit the header and change [...]


That constitutes "changing the library implementation" that I earlier
recommended. I am sure the OP would benefit from reading about (and
applying) the other fixes listed on your Web site.

V
Jul 22 '05 #4
Victor Bazarov wrote:
That constitutes "changing the library implementation"


Okay. I took that to mean "replacing the library implementation", which
is far too often an off-the-cuff suggestion.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #5
Pete Becker wrote:
Victor Bazarov wrote:
That constitutes "changing the library implementation"

Okay. I took that to mean "replacing the library implementation", which
is far too often an off-the-cuff suggestion.


Isn't English language grand? Allows me to wiggle out of any unpleasant
situation <g> especially because it's not my mother tongue.
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pelle Beckman | last post by:
Hi all, I have a few - beginners - questions: * Why can't I put object references in a std::vector, i.e std::vector<MyClass&> ? At least in doesnt work in gcc (mingw, win32) * What's the...
18
by: sd2004 | last post by:
could someone please show/help me to copy all element from "class dog" to "class new_dog" ? Note: "class new_dog" has new element "age" which should have value "my_age"...
8
by: Amit Bhatia | last post by:
User-Agent: OSXnews 2.081 Xref: number1.nntp.dca.giganews.com comp.lang.c++:817366 Hi, I have the following question: I make a list whose elements are instances of class B; list<class B>;
8
by: imutate | last post by:
I have a std::vector with each element being a class, I push_back elements and then store values in the class object, later I look at these objects and the values are null. In essence: class...
24
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public...
6
by: paul.anderson | last post by:
This code doesn't work - the first retrieval of t2 returns valid data, the subsequent do not. Please help!!! int main(int argc, char* argc){ struct Test{ int i; int j; intk; int l; }
1
by: Raghuram N K | last post by:
Hi, Following program compiles and executes successfully in windows with DevCPP compiler. When I compile the same in Linux with 'g++323' compiler I get following assignment error: cannot...
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a *...
1
by: fabian.lim | last post by:
Hi all, Im having a problem with my code. Im programming a vector class, and am trying to overload the () operator in 2 different situations. The first situation is to assign values, e.g. Y =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.