+ 1

Whats the advantage of "class" if a simple program gives the same output..??

i mean the following two programs have same output: 1). #include <iostream> using namespace std; class myClass { public: myClass() { cout <<"Hey"; } void setName(string x) { name = x; } string getName() { return name; } private: string name; }; int main() { myClass myObj; return 0; } 2). #include<iostream> using namespace std; int main() { cout<<"Hey"; return 0; }

24th Jan 2018, 11:29 AM
Mubarak Hussain
Mubarak Hussain - avatar
1 Answer
+ 8
Short answer: None. It's redundant. A class represents a blueprint of an object which has its own attributes. The example provided doesn't necessitate the use of classes.
24th Jan 2018, 11:36 AM
Hatsy Rei
Hatsy Rei - avatar