Function Pointer Help Please

class try
{
public:
int b = 20;
}
int main()
{
try try;
function(10,try.b);
functionsecpnd();

return 0;
}
function(int x, int *xs)
{
x =20;
*xs = 10
}
functionsecond()
{
x = 1
xs = 2
function(x,&xs);
}


I get cannnot convert x to *xs (20 in first function to *xs) but how do i fix that problem without moving veriables to different functions and making new ones or thee class?
Last edited on
argument x is expecting an integer (which you indeed pass in) and xs is expecting a pointer to integer (which you pass in functionsecond() but fail to do in main()). Also the functions do not specify a return type.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#include <iostream>

int a = 10, b = 20;

void swap(int *x, int *y)
{
  int s = *x;
  *x = *y;
  *y = s;
}

int main()
{
  std::cout << "a = " << a << " and b = " << b << std::endl;
  swap(&a,&b);
  std::cout << "a = " << a << " and b = " << b << std::endl;
  return 0;
}
Topic archived. No new replies allowed.