expected primary-expression before ‘int’

This is what i have example code in c++:
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
#include <iostream>

class Foo{
    public:
        void bar(){
            std::cout << "Hello" << std::endl;
        }
        
        int max(int num1,int num2) 
	{
	  // local variable declaration
	  int result;

	  if (num1 > num2)
		result = num1;
	  else
		result = num2;

	  return result; 
	}
};

extern "C" {
    Foo* Foo_new(){ return new Foo(); }
    void Foo_bar(Foo* foo){ foo->bar(); }
    int Foo_max(Foo* foo){ foo->max(int num1,int num2); }
}


after compiling it is giving error as :
foo.cpp: In function ‘int Foo_max(Foo*)’:
foo.cpp:26:37: error: expected primary-expression before ‘int’
foo.cpp:26:46: error: expected primary-expression before ‘int’

please suggest where I went wrong. Thnx..
What should this do:
1
2
3
4
int Foo_max( Foo* foo )
{
 foo->max( int num1, int num2 );
}

@keskiverto : I tried as you said but still giving same error.. please if any other solution..
That was not a solution. That was a question. Please, explain your code.
I got solution.. first I need to remove these
int
before the
num1
and
num2
. And I have to declare these two variables inside the
extern "C"
:
1
2
3
4
5
6
7
extern "C" {
    int num1;
    int num2;
    Foo* Foo_new(){ return new Foo(); }
    void Foo_bar(Foo* foo){ foo->bar(); }
    int Foo_max(Foo* foo){ foo->max(num1,num2); }
}

Thankx...
So in order to use the `Foo_max()' function you need to fill some global variables with the values that you want to use. Kind of bothersome.
Why did you make the num1 and num2 global variables?

What is Foo_max() supposed to do?
Topic archived. No new replies allowed.