Archived

This topic is now archived and is closed to further replies.

t2sherm

Strange problem with a class

Recommended Posts

I had some classes all in one file, and it was getting big, so i put each one in their own class. now i get this weird error. here is the class //this is in PowerUp.h #ifndef PowerUp_h #define PowerUp_h class CPowerUp { public: int x,y, width, height, Type; LPDIRECTDRAWSURFACE7 DDS; ~CPowerUp() {if (DDS) {DDS->Release(); DDS = NULL;} }; #endif //i took out all of the other member functions to try to figure //out what was going on then in the main cpp file i have this #include "PowerUp.h" CPowerUp PowerUp; And i get this error: D:\Pong\main.cpp(80) : error C2460: ''PowerUp'' : uses ''CPowerUp'', which is being defined I don''t get it. Thanks for any help. t2sherm ô¿ô

Share this post


Link to post
Share on other sites
well i changed the class so it looks like this:
    
class CPowerUp
{
public:
int x,y, width, height, Type;
LPDIRECTDRAWSURFACE7 DDS;

~CPowerUp();

};

CPowerUp::~CPowerUp()
{
if (DDS)
{
DDS->Release();
DDS = NULL;
}

}


And now I don''t get that error, that is really strange!!
I never got that error before, when I declared the destructor inline like that. What could possibly have caused that?
Any ideas?

t2sherm ô¿ô

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You''re missing a "}" on your definition of ~CPowerUp() in the header in your original post. You may also want to consider making the destructor virtual (unless you''re never going to inherit from the CPowerUp class).

...Syzygy

Share this post


Link to post
Share on other sites
I might be wrong(novice C++ programmer), but when you went into main.cpp, you didn''t type main() So it''s just like you were still in the class.(My C++ book says putting a .h file is just like that code in the .h file being right there. There was no main function, and therefor, you couldn''t have activated the function(I think...). Well, I hope I was right.

KA...
ME...
HA...
ME...
HA!!!

Share this post


Link to post
Share on other sites
Thanks all! it was the missing } that was causing all this problem.

quote:

I might be wrong(novice C++ programmer), but when you went into main.cpp, you didn''t type main() So it''s just like you were still in the class.(My C++ book says putting a .h file is just like that code in the .h file being right there. There was no main function, and therefor, you couldn''t have activated the function(I think...). Well, I hope I was right.


This isn''t my whole program, I just put in the part that was causing a problem. The rest of the program is a couple thousand lines, and I didn''t think there was any point in posting all that.

Well thanks everyone who took the time to read my post!

t2sherm ô¿ô

Share this post


Link to post
Share on other sites
quote:
Original post by supersaiyan

I might be wrong(novice C++ programmer), but when you went into main.cpp, you didn''t type main() So it''s just like you were still in the class.(My C++ book says putting a .h file is just like that code in the .h file being right there. There was no main function, and therefor, you couldn''t have activated the function(I think...). Well, I hope I was right.

KA...
ME...
HA...
ME...
HA!!!


Nah, the way he was declaring his variable PowerUp outside of main() just meant it would be a global variable... you can make a new instance of a class as soon as you''ve declared it. (my terminoligy may be a bit off, but the concept''s the same )


Nick - Head Designer, Llamasoft.net

--
Visit our website...

Llamasoft.net
Games, goodies and ingenuity

Share this post


Link to post
Share on other sites