If you come from the Java world, you really will find that this object in C ++ is not processed the same way. In C ++, unless explicitly stated, data is processed directly. In Java, an object is completely controlled by a virtual machine, and because of this it makes sense to allow programs to access them only by reference. Therefore, whenever you write a Java program, you must instruct the virtual machine to host the object with new and until you assign null class instance variable. Following the same principle, if you assign an object variable to another, both will refer to the same object, and a method call on both will call this method in the same base instance.
In C ++, there are two different mechanisms for getting the same result:
In C ++, both of these types are types, i.e. std::string , std::string * , std::string & are three different types. The first of them really means the structured value itself, while the other two indicate an indirect relation to a value of type std::string .
The difference between these types of indications is explained by this SO entry.
In your code, you will either have to replace all null occurrences with an empty string literal "" , or use pointers and select instances using the new operator before trying to use the object, for example, in the string cin >> word; .
source share