'Function definition is not allowed here'

Hi guys, I'm trying to run the following code, but it seems there has to be a mistake in the main() part of the program. Every time I build the program, I receive the error 'function definition is not allowed here'. Can someone help me?

#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
using namespace std;

class Algorithme {

private:
int i= 0;

struct milestone
{
int milestone_x;
int milestone_y;
char milestone_name[6];
};

int nb = 12;
milestone node[12];

struct process
{
char process_name[20];
float process_consomation;
char process_node1[6];
char process_node2[6];
};
process procedure[17];


public:

void read();
void adjmatrix();


};

void Algorithme::read() {
...

}

void Algorithme::adjmatrix() {
...

}

int main() {
Algorithme answer;
answer.read();
answer.adjmatrix();
return 0;
}




Examine the function definitions void Algorithme::read() and void Algorithme::adjmatrix()
Verify that braces are matched; that for every opening brace {, there is a corresponding closing brace }
It helps if you use code tags -> http://www.cplusplus.com/articles/jEywvCM9/
It helps if you indent your code -> https://en.wikipedia.org/wiki/Indentation_style
It helps if you post code which actually demonstrates the problem.

You managed to fix whatever it was by deleting a bunch of stuff with your ....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
using namespace std;

class Algorithme {

private:
  int i = 0;

  struct milestone {
    int milestone_x;
    int milestone_y;
    char milestone_name[6];
  };

  int nb = 12;
  milestone node[12];

  struct process {
    char process_name[20];
    float process_consomation;
    char process_node1[6];
    char process_node2[6];
  };
  process procedure[17];


public:

  void read();
  void adjmatrix();


};

void Algorithme::read()
{
//...
}

void Algorithme::adjmatrix()
{
//...
}

int main()
{
  Algorithme answer;
  answer.read();
  answer.adjmatrix();
  return 0;
}


And just in case, you need to be clear about which C++ standard your code conforms to.
1
2
3
4
5
6
7
8
$ g++ foo.cpp
foo.cpp:10:11: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
   int i = 0;
           ^
foo.cpp:18:12: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
   int nb = 12;
            ^
$ g++ -std=c++11 foo.cpp

Topic archived. No new replies allowed.