c ++ error expected initializer before 'void' when compiling main [closed]

1

I have a doubt with a class in which I implement a vector with all its functions, what happens is that when compiling, in the main I get an error that I do not understand, I have reviewed my code and I can not find an error.

This is the main:

#include<iostream>
#include<vector>
#include<cassert>
#include "vector.hpp"
using namespace std;

int main void(){
  vector a;

  vector<int> a1(8);
  a1 = {2,3,4,8,7,6,5,1};

  vector<int> a2(8);

  a2 = {4,5,8,9,2,8,7,6};

  a.suma(a1,a2);

}

This is the error:

7:10: error: expected initializer before ‘void’
 int main void(){
refiriéndose a 'int main void()'

Thank you for your help. Thank you.

    
asked by AER 09.02.2018 в 02:07
source

2 answers

2

Just the main method is poorly defined.

int main void(){
    //...
}

It should be:

int main (void){
    //...
}

Relevant documentation (in English): link

    
answered by 09.02.2018 / 03:00
source
1

While it is valid to use int main(void) in C ++, as asserted by effersion in your comment to the other answer, the most expected syntax in a C ++ program is to use any of the following statements for the function main :

int main()
int main(int argc, char* argv[])
int main(int argc, char** argv)

Which is analogous to when one expects to see headers <cmath> , <cstdlib> , etc. instead of <math.h> , <stdlib.h> , etc.

I would also like to point out that the link given in the other answer is about declaring the function main in C language (in fact at the beginning I was surprised that a reliable source on C ++ such as cppreference point out the use of int main(void) as the most standard in C ++). However, the following link , which is about C ++, shows that the most appropriate statements for the main function % are those indicated above. If you want more information, apart from the given link, you can read this excellent answer given in SO.

Finally, it is worth noting that there are also other particular statements dependent on the compiler. For example, in Microsoft Visual Studio it is valid to declare the function main of the form: void main() .

    
answered by 09.02.2018 в 18:41