You seem to have two questions on your mind.
1) How do I have a member function length?
class String {
char* fString;
public:
// constructors
String();
String(const char*);
int getLength();
....
}
int String::getLength() {
// put code in here for length...
} 2) How do I pass a string by reference?
In the case where you do have a String class I wouldn't pass a string in at all. Ideally your string class should go like this:
String helloString("Hello Dave");
cout << helloString.length();
But if you must know, this is how you pass a string into a function:
int length(char* string) {
...
}
void main() {
char string[26] = "Hi....";
length(string);
}