|
-
March 13th, 2010, 11:57 PM
#1
Visual Studio 2005 Compiler Issue
Hi,
I have just installed Visual Studio 2005 version. When I embedded my C++ program that I wrote in 2003 version into it and tried to build a solution, I got this error msg from the compiler.
error C2664:
'std::_Vector_const_iterator<_Ty,_Alloc>::_Vector_const_iterator(const
std::_Vector_const_iterator<_Ty,_Alloc> &)' : cannot convert parameter 1
from 'int' to 'const std::_Vector_const_iterator<_Ty,_Alloc> &'
This error came out in the below locations;
vector<double>::const_iterator aCommitPrimStateCiter(0);
vector<double>::const_iterator aCommitSecStateCiter(0);
vector<double>::iterator aCurrPrimStateIter(0);
vector<double>::iterator aCurrSecStateIter(0);
vector<double>::const_iterator aInitStateCiter(0)
Now apparently this definition of vectors for doubles is not accepted but I don't know what kind of conversion I should separately make or how to resolve this issue. I didn't have this problem in the previous versions...IF anyone can help, that'd be very much appreciated.
Thanks
Can
-
March 14th, 2010, 12:49 AM
#2
Re: Visual Studio 2005 Compiler Issue
Please post a complete example. What you posted doesn't even begin explaining why those errors occur.
Now apparently this definition of vectors for doubles is not accepted
???
Code:
#include <vector>
int main()
{
std::vector<double> DoubleVector;
}
This is accepted by any ANSI C++ compiler, including any version of Visual Studio.
Edit: Now I see what's wrong: Iterators are iterators, not ints. You should not be assigning an int to an iterator. You can only assign iterators to iterators.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; March 14th, 2010 at 12:58 AM.
-
March 14th, 2010, 01:02 AM
#3
Re: Visual Studio 2005 Compiler Issue
 Originally Posted by hpcan
I didn't have this problem in the previous versions...
The problem is that the older compiler implemented iterators by using an int (probably pointer) and you just happen to be lucky that this was how vector iterators were implemented in 2003.
Now that vector iterators are implemented differently in later compilers, your code is now broken. Neither VC 2003 or 2005 are wrong -- you're wrong by assuming that pointers (ints) will work as a vector iterator.
Thanks
Can[/QUOTE]
-
March 14th, 2010, 01:08 AM
#4
Re: Visual Studio 2005 Compiler Issue
Hi,
Thanks. I saw that and removed (0) all there right after I posted the thread which fixed it
(vector<double>::const_iterator aCommitPrimStateCiter),
but later in the code I need to specify these iterators zero values as;
aCommitPrimStateCiter=0.0;
where I get errors too. So these vector<double> are used in calculations and later for an if else conditional, they should be specified to 0 (error now). It is a big part of a huge project that I wrote long time ago and am now trying to figure out what I did and how I can use it with again an older version 2005.
Thanks
-
March 14th, 2010, 04:32 AM
#5
Re: Visual Studio 2005 Compiler Issue
I encountered this problem before when I compiled my VC 6.0 project in VS 2005. The problem is, as Paul McKenzie said, starting from vs2005 std::vector<T>::iterator and T * are not the same. So you cannot initialize your vector with 0 or NULL (a zero pointer) as before. And you cannot pass v.begin() to the function that expects just T *.
 Originally Posted by hpcan
but later in the code I need to specify these iterators zero values as;
aCommitPrimStateCiter=0.0;
where I get errors too. So these vector<double> are used in calculations and later for an if else conditional, they should be specified to 0 (error now). It is a big part of a huge project that I wrote long time ago and am now trying to figure out what I did and how I can use it with again an older version 2005.
Thanks
In this case it's not clear what you want to do. If you just want to zero an element pointed by aCommitPrimStateCiter you should write
Code:
*aCommitPrimStateCiter=0.0;
On other hand if you want to "zero" an iterator itself you can make the iterator invalid by assigning it the v.end() value.
But truth to be told I'm not sure this code
Code:
aCommitPrimStateCiter=0.0;
worked even in VC6.0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|