I'm working on a string class that employs pointers and I'm just having some difficulty in understanding how my print
function works here. Specifically, why does cout << pString
output the string and not the memory address of the dynamic array that it's pointing to? My understanding was that the variable pString was a pointer.
class MyString
{
public:
MyString(const char *inString);
void print();
private:
char *pString;
};
MyString::MyString(const char *inString)
{
pString = new char[strlen(inString) + 1];
strcpy(pString, inString);
}
void MyString::print()
{
cout << pString;
}
int main( )
{
MyString stringy = MyString("hello");
stringy.print();
return 0;
}