|
#include <stdio.h>
#include <string.h>
class SmartString
{
private:
char* m_sz;
public:
SmartString();
SmartString& operator = (char* sz);
char* ToStr()
{
return m_sz;
}
~SmartString();
};
int main(int argc, char* argv[])
{
SmartString* arr = new SmartString[2];
arr[0] = "Hello World";
arr[1] = "Hola' World";
printf(arr[0].ToStr());
printf(arr[1].ToStr());
delete [] arr;
return 0;
}
SmartString::SmartString()
: m_sz(NULL)
{}
SmartString& SmartString::operator = (char* sz)
{
m_sz = new char[strlen(sz) + 1];
strcpy(m_sz, sz);
return *this;
}
SmartString::~SmartString()
{
delete[] m_sz;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.