Hey Im having a problem with passing arguments into a function from a class.This is my program with just prototypes and function calls. I am confused when to pass by pointer and by reference.
Header file
Code:#ifndef STRING_HPP #define STRING_HPP #include <iostream> using namespace std; class mystring { typedef struct STRING* String; struct STRING { int size; char *theString; }; private: void validateString( mystring &theString ); public: mystring() { String->theString = NULL; String.size =0; } mystring( char *init) { newString( init ); } ~mystring() { destroyString( theString ); } mystring& destroyString( mystring &theString ); mystring& newString( char* theString ); void printString(mystring &theString); char charAt( mystring &theString, int index ); mystring& operator+( mystring &string1, mystring &string2 ); }; #endif
Function definitions
Especially when I am overloading the operator + for the purpose of concatenation, I get an error stating that 0 or 1 argument only has to be passed. Please help.Code:#include <iostream.h> #include <assert.h> #include "mystring.hpp" using namespace std; int stringCount = 0; mystring& mystring::newString( char& init ) { /*Function definition */ return( newString ); } void mystring::validateString( mystring &theString ) { /*Function definition */ } mystring& mystring::destroyString( mystring &theString ) { /*Function definition */ return( theString ); } void mystring::printString( mystring &theString ) { validateString( theString ); cout << theString->size << theString -> theString << endl ); } char* mystring::charAt( mystring &theString, int index ) { validateString( theString ); assert( index >= 0 ); assert( index < theString -> size ); return( theString -> theString[index] ); } mystring& mystring::operator+( mystring &string1, mystring &string2 ) { /*Function definition */ return( newString ); }



LinkBack URL
About LinkBacks



perator +), then the first argument is always "this" -- hence + should only take one (other) argument. In other words, choose one: