So actually, I'm gonna try to clear things up...based on what you were just saying about how you can't change the value of what the pointer points to:
Code:
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
/////////////////////////////////////////////////////////////////////////////
class String
{
private:
char* str;
public:
String(char* s)
{
int len = strlen(s);
str = new char[len+1];
strcpy(str, s);
}
~String()
{
cout << "Deleting str...\n";
delete[] str;
}
void display()
{ cout << str << endl; }
void upit()
{
char* pstr = str;
while ( *pstr ) //while value at pointer is not null
{
*pstr = toupper(*pstr);
pstr++;
}
}
};
//////////////////////////////////////////////////////////////////////////////
int main()
{
String s1 = "The end is nigh!";
cout << "s1: "; s1.display();
s1.upit(); //make uppercase
cout << "\ns1: "; s1.display();
return 0;
}
my question lies in the String::upit() function, now what you said about const char*, does that only apply to when the pointer is initialized to a string literal? As opposed to the char* in upit() that is initialized to an address?