Author | Message | Time |
---|---|---|
DarkMinion | This is the same code I've been using for years, and I just installed VS 2005, and now it's giving me a new error concerning my operators in DynBuffer....here is the code with the problematic lines sandwiched between comments: [code] #ifndef DYNBUFFER_H_INCLUDED #define DYNBUFFER_H_INCLUDED #pragma once class DynBuffer { private: unsigned long dwLen; unsigned long dwPos; char *lpszBuffer; public: DynBuffer() { lpszBuffer = 0; dwLen = 0; dwPos = 0; } ~DynBuffer() { delete [] lpszBuffer; lpszBuffer = 0; } void add(const char *lpszData); void add(const void *lpData, unsigned long dwLength); void add(unsigned long dwData); void add(int iData) { add((unsigned long)iData); } void add(unsigned short uData); void add(char bData); void add(unsigned char bData); void get(void *lpDest, unsigned long dwLength); void shift(unsigned long dwDest); void insert(const void *lpData, unsigned long dwPos, unsigned long dwLength); unsigned long length() { return dwLen; } void clear(); operator char *(void) { return lpszBuffer + dwPos; } operator unsigned long(void) { return *(unsigned long *)(lpszBuffer + dwPos); } operator unsigned short(void) { return *(unsigned short *)(lpszBuffer + dwPos); } operator char(void) { return lpszBuffer[dwPos]; } // PROBLEM LINES operator ++(int) { dwPos++; if(dwPos > dwLen) dwPos = dwLen; } operator --(int) { dwPos--; if(dwPos < 0) dwPos = 0; } operator +=(int size) { dwPos += size; if(dwPos > dwLen) dwPos = dwLen; } operator -=(int size) { dwPos -= size; if(dwPos < 0) dwPos = 0; } // END PROBLEM LINES }; #endif[/code] The error I'm getting is: [quote]1>c:\projects\dmbot\DynBuffer.h(31) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int[/quote] As I've never encountered this problem before and it was working fine with VS.NET 2003, I'm not sure what it's requiring me to do here. Any ideas? | December 8, 2005, 4:14 AM |
kamakazie | Looks like you need return types on those operators. | December 8, 2005, 5:13 AM |
DarkMinion | Fixed it...odd that it wasn't required in previous versions | December 8, 2005, 6:02 AM |
kamakazie | [quote author=DarkMinion link=topic=13452.msg136802#msg136802 date=1134021734] Fixed it...odd that it wasn't required in previous versions [/quote] Probably because it assumed int as the return type. At least, that is what the error suggests. | December 8, 2005, 6:35 AM |
Myndfyr | You might want to consider returning BOOL or void with those lines. I suppose you could return int position, or int sizeGained. It'd be interesting to say [code] if (buf++) { } [/code] because the ++ operator would still impact the value of the class and then you could evaluate the return value. *Shrug* just a thought. | December 8, 2005, 6:47 AM |
Kp | I prefer having operators return *this if there isn't anything better to return. Then it's legal to write &++(buf++). :) | December 8, 2005, 7:20 AM |
DarkMinion | I decided to just make them all return dwPos | December 8, 2005, 8:52 AM |