+ 1

please help me, i can't understand each line of this program and it's meaning why we use it? . please explain it.

#include <iostream> using namespace std; class myClass { public: myClass(string nm) { setName(nm); } void setName(string x) { name = x; } string getName() { return name; } private: string name; }; int main() { myClass ob1("David"); myClass ob2("Amy"); cout << ob1.getName(); }

25th Sep 2017, 6:25 PM
Shivani Goyal
3 Antworten
+ 1
You are defining a class myClass 3 public methods a private name
25th Sep 2017, 7:29 PM
Daniel
Daniel - avatar
+ 2
into main you are defining 2 objects, ob1 and ob2 at the end you show Name of ob1 object
25th Sep 2017, 7:31 PM
Daniel
Daniel - avatar
+ 1
In this program, you define a constructor with the a parameter and call the setName function with pass a object. second is, you make a setName function with a parameter and get the value of setName function using getName function. third is, you call the function and constructor is call only defining a object of a class.
4th Jan 2018, 1:18 PM
tarun
tarun - avatar