Hey look at this program. Its simple. Plz explain it. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hey look at this program. Its simple. Plz explain it.

#include <iostream> #include <string> using namespace std; class myClass { public: string name; }; int main() { myClass myObj; myObj.name = "SoloLearn"; cout << myObj.name; return 0; } Explain the part where you declear the class as well as the string header file and its use. My understanding of myObj.name is that it is like a pointer?? Its called a umm I forgot. Also explain the declaration part. Plzz

29th Nov 2017, 4:35 PM
Gplayer
Gplayer - avatar
4 Answers
+ 1
the string header file is required in order to use the string class and various methods implemented for strings. in main the declaration is about the object myObj, which is an instance of class my class. myObj.name is not a pointer, it is a static declares variable. for it to be a pointer, it would have to be declared like this "string* name;". in a way it is a pointer if you take its address with &name and tell it to point there *(&name). using namespace std; is needed I you don't want to type STD::con,court etc. methods of namespace STD, that is...
29th Nov 2017, 6:03 PM
Dmitrii
Dmitrii - avatar
+ 1
a variable "name" of type string
1st Dec 2017, 5:20 PM
Dmitrii
Dmitrii - avatar
0
What is the "string name "? Declared inside the class
1st Dec 2017, 1:08 PM
Gplayer
Gplayer - avatar
0
Ohhh
2nd Dec 2017, 1:49 PM
Gplayer
Gplayer - avatar