Interpreter errors handing STL objects in functions
koziscool opened this issue · comments
John Kosmicke commented
Eg, this code:
void Eratosthenes(vector<long int>* primes, long int limit){
vector<bool> primeArray(limit, true);
for( long int p = 2; p < sqrt(limit); p++){
if( primeArray[p]){
for(long int m = p*p; m < limit; m += 2 * p)
primeArray[m] = false;
}
}
primes->push_back(2);
for( long int j = 3; j < limit; j ++ 2 ){
if (primeArray[j])
primes->push_back(j);
}
}
produces this error:
input_line_9:10:42: error: expected ')'
for( long int j = 3; j < limit; j ++ 2 ){
^
input_line_9:10:8: note: to match this '('
for( long int j = 3; j < limit; j ++ 2 ){
^
Interpreter Error:
Btw, that code seems to run just fine on gcc.
John Kosmicke commented
This code has a basic typo in it, the interpreter runs it fine (when edited correctly). Should I delete this, or leave it here in case I reproduce a similar error?
John Kosmicke commented
Ok so here might be a better example, that's not a typo
long int e10(vector<long int>* primes, int limit){
long int total = 0;
vector<long int>::iterator: i = primes->begin();
while( *i < limit ){
total += *i;
i++;
}
return total;
}
Here the interpreter says:
input_line_14:2:51: error: function definition is not allowed here
long int e10(vector<long int>* primes, int limit){
^
Interpreter Error:
again runs fine on gcc