expected primary-expression before int error

Write your question here. I keep getting an expected primary-expression before ‘int’ error, and I cant really figure out why. I feel like it's something really obvious and cant notice, please help.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  army::army(string n):name(n)
 13 {
 14 
 15 add_cannon_fodder(int x);// where I get the error
 16 }
 17 int army::add_cannon_fodder(int x)
 18 {
 19 srand(time(NULL));
 20 
 21 cout<<"Number of reinforcements"<<RAND_MAX<<endl;
 22 
 23 for(int i = 0; i<10; i++){
 24 
 25 cout<<RAND_MAX<<endl;
 26 }
 27 }
you'd wanna do something like:
1
2
3
4
army::army(string n) : name(n) {
        int x = 10;
        add_cannon_fodder(x);
}


what you're doing is declaring add_cannon_fodder(int) inside your constructor (which is illegal), when what you're trying to do is call that function. Have a read through these:
http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/functions2/
Thank you very much I will make sure to take a look at these.
Topic archived. No new replies allowed.