Constructor Error
Constructor Error
Ok so I am attempting to move the sprite loading and drawing routines into is separate .h and .cpp files, and I am getting a constructor error. Can anybody help.
- Attachments
-
- UpdatedFrame.zip
- (176.4 KiB) Downloaded 153 times
What you call a bug...I call a new feature!
Re: Constructor Error
You need a default constructor. So add to D3DGraphics something like: "D3DGraphics ( ) { }". Why? In Sprite you create a graphics instance "gfx" it's like a function that takes no values, but you haven't made this function that takes no values so you need to make one.
Think it like this: You have "void DoSomething ( int x, int y );" and then you try to call it "DoSomething ( );" it's gonna give an error since you haven't made a function "void DoSomething ( );"
I know it's not the same, but think it like this and you will remember it next time.
Think it like this: You have "void DoSomething ( int x, int y );" and then you try to call it "DoSomething ( );" it's gonna give an error since you haven't made a function "void DoSomething ( );"
I know it's not the same, but think it like this and you will remember it next time.
ʕ •ᴥ•ʔ
Re: Constructor Error
I tested here and it worked. Another way I found is add a reference( D3DGraphics& gfx ) on every function you will use gfx. But I dont know which one is the best way/good programming practice.
Re: Constructor Error
no luck yet, i dunno whats wrong really lol
What you call a bug...I call a new feature!
Re: Constructor Error
Download the project you have posted, go to D3DGraphics.h, at line 32 you add D3DGraphics ( ) { }, it should work.
Re: Constructor Error
I'm getting a Sprites constructor error, I got it to build, but if I call something like Sprites sprite; in game.h I get a Sprites Constructor error
- Attachments
-
- UpdatedFrame.zip
- (176.03 KiB) Downloaded 131 times
What you call a bug...I call a new feature!
Re: Constructor Error
Ok Muttley I tried what you suggested and it will build when I call Sprite sprite; in game.h and it will run just fine. But when I close the program I get a access violation. Note: I do not get the access violation if I comment out Sprite sprite;.
What you call a bug...I call a new feature!
Re: Constructor Error
Change your constructor to default Sprites(){} and add D3DGraphics& gfx at the end of every function will use gfx.
e.g:
void DrawSprite( int xoff,int yoff,Sprite* sprite, D3DGraphics& gfx)
void DrawSpriteAlpha( int xoff,int yoff,Sprite* sprite, D3DGraphics& gfx )
void DrawChar( char c,int xoff,int yoff,Font* font,D3DCOLOR color, D3DGraphics& gfx )
void DrawString( const char* string,int xoff,int yoff,Font* font,D3DCOLOR color, D3DGraphics& gfx )
I think the access violation occurred because Sprites was trying to access private data from D3DGraphics when the destructor was called, but I'm not sure if that's exactly what happened and if it is the best way to solve the problem.
At least it works.
e.g:
void DrawSprite( int xoff,int yoff,Sprite* sprite, D3DGraphics& gfx)
void DrawSpriteAlpha( int xoff,int yoff,Sprite* sprite, D3DGraphics& gfx )
void DrawChar( char c,int xoff,int yoff,Font* font,D3DCOLOR color, D3DGraphics& gfx )
void DrawString( const char* string,int xoff,int yoff,Font* font,D3DCOLOR color, D3DGraphics& gfx )
I think the access violation occurred because Sprites was trying to access private data from D3DGraphics when the destructor was called, but I'm not sure if that's exactly what happened and if it is the best way to solve the problem.
At least it works.