Friend Function is not showing any output..
Friend Function is not showing any output. Friend function 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()
{
sum();
return 0;
}
|
I don't see why your code is not giving you your desired output. What does your ouput show? I ran your program on my laptop:
gmercer@ubuntu:~/Documents/testFolder$ clang++ -Wall -g add.cpp
gmercer@ubuntu:~/Documents/testFolder$ ls
add.cpp a.out
gmercer@ubuntu:~/Documents/testFolder$ ./a.out
Sum= 30 |
Last edited on
Same here..it works fine of Visual studio 2013...
Topic archived. No new replies allowed.