0

I have a problem in a c++ assignment that cannot be solved. Lets say this - the program works only if the membervariable (a pointer to an char-array) i public. But according to the rules it must be private and one should be able to access it through a public member-method.

Here is the definitions:

private:
   char* _strPtr();
   int _strLen;
public:
   const char* getString();

const char* String::getString() {
   return _strPtr;
 }   

And here in an overloaded member-function the problem arises

 const String operator+(const String string, const char *ch) {

   String temp;
   strcpy(temp.getString, string.getString());
   strcat(string.getString(), ch);

return temp;

 }

I get error-messages such as

 invalid arguments Candidates are ; unsigned int strlen(const char *)
 invalid arguments Candidates are ; const char* getString()

I cannot see how this could be solved. I have really tried with everything. Would be glad if someone could come with good tips.

As - I said in th beginning - the program works, but after encapsulating the membervariable and putting a const ahead of the function - it doesn't work any more.

enter image description here

user2991252
  • 760
  • 2
  • 11
  • 28

1 Answers1

1

You are defining char* _strPtr();, which is the definition of a function returning a char*. Probably what you meant was to define char* _strPtr;

vsoftco
  • 55,410
  • 12
  • 139
  • 252