Why is there error?

i get error :


1>c:\digit_string.h(39): warning C4018: '<' : signed/unsigned mismatch
1>c:\digit_string.h(40): error C2110: '+' : cannot add two pointers

1
2
3
4
5
6
7
     
        bool are_digits( const WCS_String& s )
       {
           for( char c = 0; c < strlen(s); c++) if( !std::isdigit(s) )
                 throw std::domain_error( "non numeral in string '" + s + "'" ) ;
           return true ;
       }
You probably don't have operator+ defined for whatever a WCS_String is to work with an lhs/rhs being a const char*.
so how do i fix it zhuge?
Define an operator+() for combining a WCS_String and a const char*.
http://cplusplus.com/doc/tutorial/classes2/
char is equivelant to one byte, and does not have a sign. strlen() returns an unsigned int. instead of char, use int.
1>c:\digit_string.h(40): warning C4018: '<=' : signed/unsigned mismatch
1>c:\digit_string.h(41): error C2110: '+' : cannot add two pointers


Still not working ): Pogrady
{
for( int c = 0; c <= strlen(s); c++) if( !std::isdigit(s) )
throw std::domain_error( "non numeral in string '" + s + "'" ) ;
return true ;
}
I fixed cannot add two pointers error
But another problem now:

1>c:\digit_string.h(40): warning C4018: '<' : signed/unsigned mismatch
1> Generating Code...
1>Main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall digit_string::~digit_string(void)" (??1digit_string@@UAE@XZ) referenced in function __catch$_main$0
1>C:\Project 5.exe : fatal error LNK1120: 1 unresolved externals
Have you defined a destructor for digit_string?
To fix the error:
in WCS_String you need to declare:
friend char* operator+(char* lhs, WCS_String& rhs);

Then you need a non-member function:
1
2
3
char* operator+(char* lhs, WCS_String& rhs)
{
}

In this function you need to manually append your WCS_String to the char* and return a char*.

That will now allow you to have a char* on the left and a WCS_String on the right of a + sign. If you also want to have a WCS_String on the left and a char* on the right, it's a little easier. Just add this to the WCS_String class and manually append a char* to your string.
1
2
3
char* operator+(char* rhs) // *this is the lhs
{
}


To fix the warning:
for( unsigned char c = 0; c < strlen(s); c++) if( !std::isdigit(s) )
Last edited on
Topic archived. No new replies allowed.