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
4 Respostas
+ 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...
+ 1
a variable "name" of type string
0
What is the "string name "? Declared inside the class
0
Ohhh