Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: DarkMinion on December 07, 2005, 10:14 PM

Title: Help with an error please
Post by: DarkMinion on December 07, 2005, 10:14 PM
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:


#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


The error I'm getting is:

Quote1>c:\projects\dmbot\DynBuffer.h(31) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

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?
Title: Re: Help with an error please
Post by: dxoigmn on December 07, 2005, 11:13 PM
Looks like you need return types on those operators.
Title: Re: Help with an error please
Post by: DarkMinion on December 08, 2005, 12:02 AM
Fixed it...odd that it wasn't required in previous versions
Title: Re: Help with an error please
Post by: dxoigmn on December 08, 2005, 12:35 AM
Quote from: DarkMinion on December 08, 2005, 12:02 AM
Fixed it...odd that it wasn't required in previous versions

Probably because it assumed int as the return type. At least, that is what the error suggests.
Title: Re: Help with an error please
Post by: MyndFyre on December 08, 2005, 12:47 AM
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

if (buf++) {

}

because the ++ operator would still impact the value of the class and then you could evaluate the return value.  *Shrug* just a thought.
Title: Re: Help with an error please
Post by: Kp on December 08, 2005, 01:20 AM
I prefer having operators return *this if there isn't anything better to return.  Then it's legal to write &++(buf++). :)
Title: Re: Help with an error please
Post by: DarkMinion on December 08, 2005, 02:52 AM
I decided to just make them all return dwPos