Strange problem with a class

Started by
5 comments, last by t2sherm 23 years, 8 months ago
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 ô¿ô
t2sherm ô¿ô
Advertisement
hmm, maybe you declared the class twice. I''d have to see more of your code to figure it out.

It might help if you define CPowerUp::~CPowerUp() in a different file. Did you show all of PowerUp.h?
For a good time hit Alt-F4! Go ahead try it, all the cool people are doing it.
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 ô¿ô
t2sherm ô¿ô
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
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!!!
KA...ME...HA...ME...HA!!!
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 ô¿ô
t2sherm ô¿ô
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
Nick - Head Designer, Llamasoft.net--Visit our website...Llamasoft.netGames, goodies and ingenuity

This topic is closed to new replies.

Advertisement