Hi,
I want to make an array of strings like this:
string s[4]={"a", "ab", "abc", "abcd"};
Then I want to write a class with a pointer to a string (and not an array of string pointers).
class someclass{
public:
// constructors and other member functions here
private:
string *sPtr;
int numElements;
};
I want to pass the string, s, to the constructor for the class I wrote (and maybe even use it in the initializer list) and then use the class object's pointer to s to find the length of each element of array s.
someclass::someclass(int arraysize, string s[]): numElements(arraysize), sPtr(s)
{
//do stuff
numElements=arraysize;
sPtr=&s;
}
In the function where I declared s I would do this:
someclass myobject(4, s); // string s[4]={"a", "ab", "abc", "abcd"}; from above
In a member function of class someclass I would do something like this:
cout<<sPtr[1].length()<<endl; //expect to get the size of s[1]
Obviously this didn't work or I wouldn't have posted ;)
I searched online for quite a while but most people prefer to use char* and those that do deal with <string> don't even bother with arrays of strings, their tutorials are too basic.
There are so many places where I could be going wrong :S
Thanks for reading my thread.