Friend Function is not printing anything !!

Where is the error in the following code ?
The program is not printing anything ..

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
#include<iostream>
using namespace std;

class add 
 { 

private:
int a;
int b;

private:

void set_ab(int i ,int j);
friend void sum();
 };

void add::set_ab(int i,int j)
{
a=i;
b=j;
}

void sum()
{
add x;
x.set_ab(10,20);
cout << "Sum= " << x.a+x.b;
}


int main()
{
void sum();
return 0;
}




Using void was a mistake !!

BUT..

After removing void it is still not printing anything !!
Last edited on
1
2
3
4
5
int main()
{
void sum(); // remove the void specifier here. By declaring void, you are in effect declaring a prototype of another function.
return 0;
}

This

void sum();

is not a function call. It is a function declaration.
Topic archived. No new replies allowed.