Problem with constructor!

Started by
4 comments, last by ZomeonE 24 years, 6 months ago
Ok, I''ve got a standard class: class CSurface { public: // Globals LPDIRECTDRAWSURFACE7 surface; // Functions CSurface(); ~CSurface(); void LoadFromBMP(char* filename, LPDIRECTDRAW7 lpdd); // Load from BMP image private: } and: #include "csurface.h" CSurface::CSurface() { } CSurface::~CSurface() { if(surface) { surface->Release(); surface = NULL; } } But I get the error: error C2533: ''CSurface::CSurface'' : constructors not allowed a return type
Advertisement
Try putting a semicolon at the end of your class declaration.

If you just copied the code over try putting a semi-colon after the class declaration
Else
joeG
Yes, of course!
Sorry to bother you guys!
Hi there!

I know you already got an answer to your question but I would just like to make a small comment on your code here:

You should always clear the pointers at initialization, in this case you should add surface = 0; to your CSurface constructor.

You will probably never notice any difference since you allocate memory for it in LoadFromBMP(), or so I guess, but if you are not careful you might try to delete memory that is not allocated.

Hehe,

Even better code would be

CSurface::CSurface() : surface(NULL)
{
}

Sorry, I just had to add that

This topic is closed to new replies.

Advertisement