template<typename T> T SmartIO::Peek() {
T temp;
T tempReturn;
while(true){
temp = *(T*)&buffer[ptrSeek];
if(temp !=0){
ptrSeek++;
tempReturn += *(T*)&buffer[ptrSeek];
}
else{
break;
}
}
return tempReturn;
}
so what i want to do is , start reading from ptrSeek start looping, adding the value to temp and check if temp’s value !=0 add this value to tempReturn, and once the temp’s value is 0 break the loop and return the tempReturnbut, but it’s keep giving me this error :
error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion)
how can i solve this issue here?
There is a fundamental issue with your template code if you are attempting to compare an arbitrary type
Tagainst the numeric constant 0, which you are doing in the code here:The problem here is that
Tis an arbitrary type (in this case, you seem to be instantiating the template withstd::string), but you are expecting that type to be comparable to 0. This is perfectly fine – it just restrictsTto be types that can be compared against 0 – but from the fact that you’re reporting this as an error I’m not sure if you’re aware of this.Your options are either to not instantiate this template with
std::stringas an argument (the way it’s written, I don’t think you’re supposed to be able to do this, since it looks like the function keeps adding values together of some type), or to debug the template and change its behavior. I’m not quite sure what you want the code to do, so in the latter case I’m not sure how I can assist.Hope this clarifies things!