Problem with my automatic pointer implementation

L

Lothar Behrens

Hi,

I assume, to be right here :)

My automatic pointer implementation is packaged into a macro, that could
be placed into a class definition.

I have the following code (snippets) that brought me to a problem:

UAP(lb_I_Database, database, __FILE__, __LINE__)
UAP(lb_I_Query, sampleQuery, __FILE__, __LINE__)


long l; // This buffer gets overwritten.
char buf[100]; // This not.

wxWindow* firstButton;
wxWindow* prevButton;
wxWindow* nextButton;
wxWindow* lastButton;

If I do not include this long l or the char buffer, I get overwritten
my real in use window member firstButton.

The code line that invokes this overwrite is as follows:

sampleQuery = database->getQuery(0);


Thanks for any help

Lothar


I think these code may be of relevance of the macro:

#define UAP(interface, Unknown_Reference, file, line) \
class UAP##Unknown_Reference { \
public: \
UAP##Unknown_Reference() { \
_autoPtr = NULL; \
_line = -1; \
_file = NULL; \
allowDelete = 1; \
} \
UAP##Unknown_Reference(const UAP##Unknown_Reference& _ref) { \
_file = NULL; \
if (_ref._file) { \
_file = new char [strlen(_ref._file) + 1]; \
_file = strcpy(_file, _ref._file); \
} \
_line = _ref._line; \
} \
void operator=(const UAP##Unknown_Reference& _ref) { \
if (_file != NULL) { \
delete [] _file; \
if (_ref._file) { \
_file = new char [strlen(_ref._file) + 1]; \
_file = strcpy(_file, _ref._file); \
} \
} \
_line = _ref._line; \
} \
virtual ~UAP##Unknown_Reference() { \
} \
} \
UAP##Unknown_Reference& LB_STDCALL operator = (interface* autoPtr) { \
_autoPtr = autoPtr; \
return *this; \
} \
protected: \
interface* _autoPtr; \
int _line; \
char* _file; \
int allowDelete; \
}; \
\
interface* _UAP##Unknown_Reference; \
UAP##Unknown_Reference Unknown_Reference;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top