pointers are one of the hardest concepts to understand in C/C++. I would encourage you to use a textbook or a good tutorial to help you get started. Online I think Liberty's Teach Yourself C++ in 21 days is best one available if you don't already know C. If you know C, then Bruce Eckels Thinking in C++ has a lot going for it as well. Learning how to use pointers is hard enough when using a reputable textbook, let alone trying to do it piecemeal.
Here's a few tips. Pointers are like other variables in that they have to be created using a given type, they have a name, they have an address, and they contain information. The information they contain is the address of another variable/function. Therefore, trying to assign an int to a pointer as in the following line from your code won't accomplish the purpose you are trying:
st = strlen(a.st)+strlen(temp)+1;
Pointers can point to memory on the stack or on the heap (aka free store, dynamic memory, whatever you call it). However, if you assign dynamic memory to the pointer then you need to follow the appropriate protocol to release it. If you allocate the memory with the new operator then you need to release it with the delete operator and if you allocate it with malloc then you release it with free. Don't mix and match as you do in the program, however.
Because using pointers is difficult I would encourage you to learn how to comment your code. If you do so then you can pick up other booboos like below:
for (int i=0;ch[i]!='\0';i++);
st=new char (i);
I think you are trying to determine how much memory to allocate to str so you can assign the value of ch to str later in the function, but withought comments I can't be sure. Assuming that is the intent, then you don't want the semi-colon after the closing brace of the for loop as it then makes the for loop irrelevant. Likewise, the second line is a little unclear. Generally the syntax is:
st = new char;
for a pointer to a single char and
st = new char[i];
for a pointer to a char array of size i. The new operator will create one or more objects of the type indicated using a constructor of the type indicated. The default constructor will be used for arrays and the default constructor will be used by default for individual objects. You can indicate a different constructor by passing arguments to a non-default constructor of a user defined class as desired:
struct car
{
car(int);
//etc.
};
car *pCar = new car(4);
calls the non-default constructor for class car passing it the value of 4. However, primitive types like char don't have non-default contstructors. Therefore the syntax of the second line of the last code snippet is off somehow, depending on what you are trying to do. The simplest sequence I can think of would be this:
Code:
//constructor using an input string represented by a char pointer
str::str(char *ch)
{
//determine length of input string
length = strlen(ch);
//assign adequate memory to st to hold input string
st = new char[length + 1];
//copy input string to st
strcpy(st, ch);
}