I'll try to explain this to you as far as my limited skills allow.
string *kasi;
this defines kasi as a pointer to a string object. Therefore
kasi
represents the adress where an object is stored in memory.
If you want the object itself you'd use *kasi.
Therefore if you want to call a function of the object pointed to by kasi you'd use:
(*kasi).function()
C++ provides another way of doing exactly the same thing, consider it an shortcut
kasi->function()
.
kasi.function()
won't work because you're asking a memory adress to call some function. Memory adresses are just what we call them, adresses. You wouldn't knock on a street adress of a house, you'd knock on the house in that street adress. Understand? Hope so.
As for the second problem:
An array is nothing more than a contiguous space in memory to store something.
when you do something like this;
1 2
|
string *kimber;
kimber= new string[20];
|
you're assigning the adress of the first element in the array to kimber.
cout expects, strings wise, that you pass the adress of the first element.
cout will then read element by element until it finds the null byte '\0' character.
Therefore if you pass *kimber to cout instead of an adress you're passing the value of the first element. It's the same as if you're doing kimber[0]. cout then treats this as a lonely char and not a string type.
EDIT: I've only realized this:
1 2 3 4 5 6 7 8
|
kimber = new string [20];
kimber[0] = "t";
kimber[1] = "r";
kimber[2] = "i";
kimber[3] = "t";
kimber[4] = "a";
cout<<*kimber;
|
string objects are different from c style strings.
string[20] is an array of 20strings not a string with 20 chars.
You could initialize kimber[0]="This is a C++ string".
Then the first char of kimber[0] would be kimber[0][0]. What I said earliar applies only to c style strings. Sorry