0

Error message:
...error C3867: 'temp::addition': function call missing argument list; use '&temp::addition' to create a pointer to member

#include "stdafx.h"
#include <iostream>

using namespace std;

struct temp
{
	int addition(int x, int y)
	{return (x + y);}

	int operation (int x, int y, int (*functocall)(int,int))
	{
		int g;
		g = (*functocall)(x,y);
		return (g);
	}
};


int main ()
{
  int m;
  
  temp momo;

  m = momo.operation(3, 4, momo.addition);  // !!!???
  cout << m;

  cin.get();
  return 0;
}
4
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by firstPerson
0
m = momo.operation(3, 4, momo.addition);

Try to send a reference of that function .

m = momo.operation(3, 4, &momo.addition);
0

Try to send a reference of that function .

m = momo.operation(3, 4, &momo.addition);

syntax error, dude.

Edited by mike_2000_17: Fixed formatting

0

Easy way out. Make member func static :

#include <iostream>

using namespace std;

struct temp
{
	static int addition(int x, int y)
	{return (x + y);}

	int operation (int x, int y, int (*functocall)(int,int))
	{
		int g;
		g = (*functocall)(x,y);
		return (g);
	}
};


int main ()
{
  int m;
  
  temp momo;

  m = momo.operation(3, 4, temp::addition);  
  cout << m;

  cin.get();
  return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.