found your problem!!!!!
you masked the class variable char *cpString with a local one
get rid of
Code:
char * cpString = new char[iLength];
// and put this
cpString = new char[iLength];
here is the working version of it
Code:
#include <iostream>
using namespace std;
class CIS025String{
private:
char *cpString; // Pointer to store the String Object ( Address of block of memory assigned for the string
// when the object is created).
public: CIS025String(); // Default Constructor
CIS025String(const char *cpS ); // Constructor
~CIS025String(); // Destructor
int GetLength();
int IsEmpty();
private: int CIS025String::GetSize(const char *cpS);
};
/********************
* Class CIS025String.
* Function Definitions
*
*
********************/
int main()
{
CIS025String s3 = "Hello!"; // 7 Chars ( 6 chars + '\0' )
cout<< s3.IsEmpty();
return 0;
}
CIS025String::CIS025String() //Default Constructor
{
cout << "Using Default Constructor" << endl;
// doesn't need to allocate memory on the heap
}
CIS025String::CIS025String(const char* cpS) //Constructor
{
cout << "Using Constructor" << endl;
int iLength = GetSize(cpS) + 1;
cout << "String Length = " << iLength-1 << endl;
char * cpString = new char[iLength];
for(int i = 0; i < iLength; i++ )
{
cpString[i] = cpS[i];
//cout << cpS[i] << endl;
}
cout << cpString << endl; // Will output the String.
}
CIS025String::~CIS025String() //Destructor Declaration
{
delete [] cpString;
cpString = 0;
}
int CIS025String::GetSize(const char *cpS)
{
int iLength = 0; // Character Counter
const char *ptr = cpS;
while(*ptr)
{
iLength++;
//cout << ptr << endl;
ptr++;
}
return iLength;
}
int CIS025String::GetLength() //returns String Length (not inclusding terminating '\0'
{
int iLength = 0; // Character Counter
char *ptr = 0;
ptr = cpString;
while(*ptr)
{
iLength++;
ptr++;
}
return iLength;
}
int CIS025String::IsEmpty()
{
char *ptr = 0;
ptr = cpString;
cout << *ptr;
if(!*ptr)
{
return 0;
}
else
{
return 1;
}
}
i know it is syntax correct..but logically it doesnt work..so i fixed it... you're welcome