Is this a good start?

Started by
18 comments, last by SSJCORY 18 years, 10 months ago
Where are your include guards for your header files? Remember what happens when you use header files that declare classes/structs/variables more than once and do not have include guards [wink]
Advertisement
I have inclusion guards on all my headers now so thats not the problem.
I need to use the instance of cAnimate boom in main and in my cMap class. Is there a way to do this?
-Cory
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
Just a couple of things I found to note (not specific to your current problem)
But, your variable naming seems pretty good (easy to follow without having to lookup what the method of member is doing)

But, well... Comments. The program is small now, so it's easy to follow and keep it all in your head, but when it gets ten times this size, and you put it down for a month or two to work on something else (not saying you will, but if you do) then you're -really- going to welcome some comments explaining what things are and why you did them a certain way. Yes, you can probably read through the code and figure it out, but a few well placed comments could save you a lot of time in that figuring process.

As for your current problem, without seeing where you changed the code, I'd say either you missed a header guard, or you forgot to take the definition out of Main.cpp when you added it to map.cpp
Ah sorry, just caught your last post. Your sharing a global instance of the class acrossed multiple files? I think what your looking for is an "extern" reference.

Basically, use cAnimate boom in main.cpp like normal, then in the header files for map, or animate declare:

extern class cAnimate boom;

And that should allow you to use the single reference acrossed those files.

(I think I have that syntax correct, its been a month or two since I touched C++)
i use boom.addFrame in main.
also i use boom.setx,y,activate in map.
How do i make it so i can use it in botH?
i have all the inclusion guards here i'll show you
player.h
#include<string>#include<windows.h>#include<sstream>#ifndef PLAYER_H#define PLAYER_Husing namespace std;class cPlayer{private:	int x;	int y;	int life;	string name;	HBITMAP visual;public:	int getX();	int getY();	HBITMAP getVisual();	string getName();	void setX(int newx);	void setY(int newy);	void setVisual(HBITMAP newbitmap);	cPlayer();	cPlayer(int startx,int starty,string newname);	cPlayer(HBITMAP hbitmap);	cPlayer(HBITMAP hbitmap,int startx,int starty);	void display(HWND hwnd);};#endif

animate.h
#include<vector>#include<windows.h>using namespace std;#ifndef ANIMATE_H#define ANIMATE_Hclass cAnimate{private:	vector <HBITMAP>animation;	bool active;	int currentframe;	int frametime;	int lastupdate;	int x;	int y;	vector <int>width;	vector <int>height;public:	cAnimate();	int getLastUpdate();	int getFrameTime();	void addFrame(HBITMAP newframe,int newwidth,int newheight);	void removeFrame(int index);	void activate();	bool isActive();	int getCurrentFrame();	void setX(int newx);	void setY(int newy);	int getX();	int getY();	int getWidth(int index);	int getHeight(int index);	void display(HWND hwnd);}boom;#endif

map.h
#include<vector>#include<windows.h>#include"player.h"#include"animate.h"#ifndef MAP_H#define MAP_Husing namespace std;class cMap{private:	int width;	int height;	int mousex;	int mousey;	vector<cPlayer> players;	int currentplayer;public:	int getwidth();	int getheight();	cMap();	cMap(int newwidth,int newheight);	void setMouse(int x, int y);	int getMouseX();	int getMouseY();	void moveplayer(int direction);	void addplayer(cPlayer newplayer);	void removeplayer(int index);	void display(HWND hwnd);	int didcollide(cPlayer player1,cPlayer player2);	void isClicked(cPlayer player);	cPlayer getPlayer(int playerid);};#endif

i did them right didnt i?
-Cory
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
I cant get taht extern thingy to work i still get the same errors :'(
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
My understanding of header guards says that probably wont work correctly. Header guards only protect against data definitions (right guys?) But Data declarations will still get you linker errors. So,

animate.h
	void display(HWND hwnd);}boom;#endif


Your boom there will probably cause some problems.

instead, do this.
animate.h
	void display(HWND hwnd);};extern class cAnimate boom;#endif


main.cpp
#include"player.h"using namespace std;cAnimate boom;
DOOD YOU ARE LIK EA GOD!!!!!!!!!
Thanks a lot :-D
-Cory you get rep!
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
Heh, thanks ;)

I just remember that header guards and extern references were one of those things that was difficult to wrap my mind around at first. Now that I've been using them for years, its almost like second nature.
Ok i've got all this working is this generally the direction one would go in to make a game?
-Cory
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|

This topic is closed to new replies.

Advertisement