whats wrong with the above code;\Code:#include<iostream.h> #include<conio.h> class myclass { private: int a,b; public: add() { cin>>a; cin>>b; cout<<a+b; } }; int main() { myclass obj; obj.add(); return 0; }
whats wrong with the above code;\Code:#include<iostream.h> #include<conio.h> class myclass { private: int a,b; public: add() { cin>>a; cin>>b; cout<<a+b; } }; int main() { myclass obj; obj.add(); return 0; }
1. Using non-standard headers iostream.h and conio.h -- just #include <iostream>
2. No return type declared for the add() method
baahahha thanks
forgot the type for ADD, that solved it thanks man ;xCode:#include<iostream.h> #include<conio.h> class myclass { private: int a,b; public: void add() { cin>>a; cin>>b; cout<<a+b; } }; int main() { myclass obj; obj.add(); return 0; }
You don't even need conio.h anyway.
Get rid of the .h after iostream ( As Brewbuck suggested ) and use std:: infront of cout and cin.
Double Helix STL
Your function Add() does not do its thing: it does not only add two integer values, it also sets the private attributes with their values.
Why don't you split this in three functions? Two which set 'a' and 'b', and one who adds them.
This leads to a more understandable main program: we see what we do.
and indent your code