0
How this will be error free
I have to do calculations in one class sample only but it have many friend functions in it and all the functions will be called and performed from the same class but if it will error free then only I can program more friend functions of division multiplication in it and also call it in int main() function. Please help me https://code.sololearn.com/cdc9P8796Hl6/?ref=app https://code.sololearn.com/cdc9P8796Hl6/?ref=app
5 Respuestas
+ 3
See this your program giving error becoz you created another constructor which have 2 argument and both are int type and in before constructor which u created its also have 2 int argument . So its giving errors . Yes u can write for multiplication division also but first read application of friend function your member function are also public so u don't need to do it.
Once check it
#include <iostream>
using namespace std;
class sample{
int a, b, c, d, w, x, y, z;
public:
sample(int w, int x){
a=w;
b=x;
}
friend int B(sample C);
friend int D(sample E);
};
int B(sample C){
return(C.a+C.b);
};
int D(sample E){
return(E.c-E.d);
};
int main() {
sample C1(100, 2);
sample E1(100, 10);
int sum=B(C1);
cout<<sum;
int sub=D(E1);
cout<<sub;
return 0;
}
+ 3
You created two constructor and both have same arguments int int this is errors . Rule of constructor signature should be different.
0
Can you redescribe your statement? I don't get it.
0
I have created class sample
I have given parameters x and y
It have to declare many friend functions for sample class
But i am facing errors
0
But I am not getting expected result value for sub variable check the operations regarding sub variable of int datatype