Wrong constructor used for vector<string>. 
Author Message
 Wrong constructor used for vector<string>.

Hi,
I have problems compiling the following code in VC++ 6.

Can someone give me a clue on how to work around the
problem.
(The code compiles with VS .NET)

Regards,
Peter

---
#include <string>
#include <vector>
int main(int argc, const char *argv[]) {
  std::vector<std::string> a(&argv[0], &argv[argc]);
  return 0;

Quote:
}

---
I guess the compiler finds the following constructor:

explicit vector(size_type n, const T& v = T(), const A& al
= A());

instead of this one:
vector(const_iterator first, const_iterator last,
    const A& al = A());

I get the following error message:

Edited version:

vector<string>::vector<string>(unsigned int,const string
&,const class allocator<string > &)' :
cannot convert parameter 1 from 'char ** ' to 'unsigned
int'

Full version:

d:\private\argtest\m.cpp(5) : error C2664: '__thiscall
std::vector<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >,class
std::allocator<class std::basic_string<char,struct
std::char_traits<char>,class std::all
ocator<char> > > >::std::vector<class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,class std::allocator<class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > > >(unsigned int,con
st class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >
&,const class std::allocator<class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > > &)' : cannot convert parameter 1
from '
char ** ' to 'unsigned int'



Tue, 02 Mar 2004 23:37:31 GMT  
 Wrong constructor used for vector<string>.

Quote:

> I have problems compiling the following code in VC++ 6.

> Can someone give me a clue on how to work around the
> problem.
> (The code compiles with VS .NET)
> .....
> #include <string>
> #include <vector>
> int main(int argc, const char *argv[]) {
>   std::vector<std::string> a(&argv[0], &argv[argc]);

The problem is that the V6 library contains none of the member
template functions and constructors required by the C++ Standard.
(They're in V7 and our upgrade library.) None of the remaining
constructors can handle these arguments -- not even the
const_iterator one that you think might do. It's pretty messy,
and dangerous, to add just some of the missing member templates
to the <vector> shipped with V6. Your safest bet is to replace
this constructor with an empty constructor and a loop to populate
the vector. If you're ambitious, you can try using a back inserter
with the copy template function.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com



Wed, 03 Mar 2004 00:43:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. <<<<<<<Parsing help, please>>>>>>>>

2. vector<string> data loss

3. problem with vector <string>

4. Warnings for std::vector<std::string>

5. vector<string> causes LNK2005/4006 errors

6. vector <string>

7. typedef std::vector<std::string> Vector_String

8. question from vector<string>

9. convert string to vector<char>

10. vector<std::string>

11. Compiler warning with vector<string>

12. File Format conversion, ascii freeform -->.csv <-->.wk1<-->dbf<-->?HELP

 

 
Powered by phpBB® Forum Software