How this will be error free | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

13th Sep 2020, 9:33 AM
Atul Prakash
Atul Prakash - avatar
5 Answers
+ 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; }
13th Sep 2020, 10:39 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
You created two constructor and both have same arguments int int this is errors . Rule of constructor signature should be different.
13th Sep 2020, 10:58 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Can you redescribe your statement? I don't get it.
13th Sep 2020, 9:49 AM
你知道規則,我也是
你知道規則,我也是 - avatar
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
13th Sep 2020, 10:54 AM
Atul Prakash
Atul Prakash - avatar
0
But I am not getting expected result value for sub variable check the operations regarding sub variable of int datatype
13th Sep 2020, 11:10 AM
Atul Prakash
Atul Prakash - avatar