+ 2

What is the error in this .... Related to constructor overloading plz help and solve my query

#include <iostream> using namespace std; class rel { float c; public: rel(int a) { cout<<"a is"<<a; } rel(int a,int b) { c=a+b; } rel(float a,int b) { c=a+b; } rel(float a,float b) { c=a+b; } void display() { cout<<"sum is"<<c<<endl; } }; int main() { rel obj(3); rel obj2(5,6); rel obj4(5.6,8); rel obj3(6.8,7.3); obj.display(); obj2.display(); obj3.display(); obj4.display();

22nd Dec 2017, 6:56 PM
Kratos
Kratos - avatar
10 Answers
+ 1
ohh.. so in constructor overloading we must use f with float values..and in double ! did we use d also with double values?
22nd Dec 2017, 7:58 PM
Kratos
Kratos - avatar
0
@immortal but when we use this using only single float, then it is taking it float without uski f
22nd Dec 2017, 7:49 PM
Kratos
Kratos - avatar
0
#include <iostream> using namespace std; class rel { float c; public: /* rel(int a) { cout<<"a is"<<a; } rel(int a,int b) { c=a+b; }*/ rel(float a,int b) { c=a+b; } /* rel(float a,float b) { c=a+b; }*/ void display() { cout<<"sum is"<<c<<endl; } }; int main() { /*rel obj(3); rel obj2(5,6); rel obj4(5.6,8);*/ rel obj3(6.8,7); obj3.display(); /*obj2.display(); obj3.display(); obj4.display();*/ return 0; } this is working sorry not justyfied with your last reply
22nd Dec 2017, 7:54 PM
Kratos
Kratos - avatar
0
when it taking a decimal value as float nd when double?
22nd Dec 2017, 7:55 PM
Kratos
Kratos - avatar
0
Here is ur complete program #include <iostream> using namespace std; class rel { float c; public: rel(int a) { cout<<"a is"<<a<<endl; } rel(int a,int b) { c=a+b; } rel(double a,int b) { c=a+b; } rel(double a,double b) { c=a+b; } void display() { cout<<"sum is"<<c<<endl; } }; int main() { rel obj(3); rel obj2(5,6); rel obj3(5.6f,8); rel obj4(6.8f,7.3f); obj2.display(); obj3.display(); obj4.display(); return 0; }
24th Dec 2017, 3:57 AM
kishan Gupta
kishan Gupta - avatar
0
thanxx @kishan Gupta and@immortal
26th Dec 2017, 4:57 AM
Kratos
Kratos - avatar