Question:
C++ lists & vectors error?
A
2013-07-12 17:14:59 UTC
Currently working on a small game in the Allegro library & C++, now I'm at the point where it just decides to troll me.

Normally, for things like enemies, missiles etc. I would use either a std::vector or a std::list, and an iterator to iterate through each one.

I would usually do something like this:

typedef vector missiles;
missiles m;
vector::iterator missilesIterator;

Then in my classes update method, it would be:

for (missilesIterator = m.begin(); missilesIterator != m.end(); ++missilesIterator) {
missilesIterator->Update();
}

Or something like that.

This usually works fine, suddenly I'm getting these errors:

Error C2143: syntax error: missing ) before 'string'
Error C2664: '_CrtDbgReportW' : cannot convert parameter 5 from 'int' to 'const wchar_t*'
Error C2059: syntax error : ')'

I have absolutely no idea what any of these errors mean, or how to correct them. I've never had this happen before.
Four answers:
MichaelInScarborough
2013-07-13 00:29:03 UTC
Why don't you just post your code around the call to function ReportW? There is a parameter error.

The following code works ...



#include

#include

using namespace std;

struct Missile{

    void Update(){}

    };

int main()

    {

    typedef vector missiles;

    missiles m;

    vector::iterator missilesIterator;

 

//Then in my classes update method, it would be:

 

    for (missilesIterator = m.begin(); missilesIterator != m.end(); ++missilesIterator) {

        missilesIterator->Update();

        }

    }

 
husoski
2013-07-13 00:34:00 UTC
Focus on the earliest error in the source that's being compiled. I'd have to see the "or something like that" to figure out what's wrong, exactly. Once thing that gets messages like that is use of an iterator instead of a const_iterator when something like a const reference is passed as a function argument. To use those:



vector::const_iterator missileiterator;



for (missileiterator = m.cbegin(), missileiterator != m.cend(); ++missileiterator)

...
I Don't Eat Vodka
2013-07-13 16:12:57 UTC
"Error C2143: syntax error: missing ) before 'string'

Error C2664: '_CrtDbgReportW' : cannot convert parameter 5 from 'int' to 'const wchar_t*'

Error C2059: syntax error : ')'"



These errors seem nothing like a error with iterator syntax. They seem like a missing bracket.
-DC-
2013-07-13 00:16:53 UTC
Run in debug and you'll find the answer (i.e. use a real IDE like Eclipse).


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...