error expected Primary-Expression before ' ' token

Asked

Viewed 791 times

-2

Error on line 21.

#ifndef __STRING_H__
#define __STRING_H__

#pragma warning(disable: 4786)
#include <string>
#include <vector>

const int MAX_RESP = 4;

typedef std::vector<std::string> vstring;


bool isPunc(char c);
void cleanString( std::string &str );
void UpperCase( std::string &str );
void copy(char *array[], vstring &v);

template<typename T>
void shuffle(T &array, size_t size) {
    for(int i = 0; i < size; ++i) {
        int index =() % size;
        std::swap(array[i], array[index]);
    }
}

#endif
  • 4

    It’s your second question, and they’re both typos. It would be good to pay more attention or start doing simpler things until you get more used to the language and errors presented.

  • Did the answer solve your problem? Do you think you can accept it? If you don’t know how you do it, check out [tour]. This would help a lot to indicate that the solution was useful to you and to give an indication that there was a satisfactory solution. You can also vote on any question or answer you find useful on the entire site (when you accept you will have the 15 points required).

1 answer

1

I believe it was just a typo, since the operator % You need to have two operands, you only have one. Parentheses are there without meaning. Maybe the intention was to put an expression in there and its result be used as first operand. Or maybe it’s something simpler. I switched the () by the variable i and compiled, I don’t know if it was the intention:

#include <string>

template<typename T>
void shuffle(T &array, size_t size) {
    for (int i = 0; i < size; ++i) {
        int index = i % size;
        std::swap(array[i], array[index]);
    }
}
int main() {}

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.