Constructor Error

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
XxWalKaxX
Posts: 244
Joined: June 11th, 2012, 7:15 pm

Constructor Error

Post by XxWalKaxX » November 2nd, 2012, 9:02 pm

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!

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Constructor Error

Post by LuX » November 2nd, 2012, 9:59 pm

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.
ʕ •ᴥ•ʔ

User avatar
XxWalKaxX
Posts: 244
Joined: June 11th, 2012, 7:15 pm

Re: Constructor Error

Post by XxWalKaxX » November 3rd, 2012, 3:09 am

I'm so lost :( lol
What you call a bug...I call a new feature!

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Constructor Error

Post by LuX » November 3rd, 2012, 8:46 pm

Hmm... Did you get it working anyway?
ʕ •ᴥ•ʔ

Muttley
Posts: 39
Joined: October 19th, 2012, 6:00 am

Re: Constructor Error

Post by Muttley » November 3rd, 2012, 11:47 pm

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.

User avatar
XxWalKaxX
Posts: 244
Joined: June 11th, 2012, 7:15 pm

Re: Constructor Error

Post by XxWalKaxX » November 4th, 2012, 5:48 am

no luck yet, i dunno whats wrong really lol
What you call a bug...I call a new feature!

Muttley
Posts: 39
Joined: October 19th, 2012, 6:00 am

Re: Constructor Error

Post by Muttley » November 4th, 2012, 6:03 am

Download the project you have posted, go to D3DGraphics.h, at line 32 you add D3DGraphics ( ) { }, it should work. ;)

User avatar
XxWalKaxX
Posts: 244
Joined: June 11th, 2012, 7:15 pm

Re: Constructor Error

Post by XxWalKaxX » November 4th, 2012, 8:30 am

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!

User avatar
XxWalKaxX
Posts: 244
Joined: June 11th, 2012, 7:15 pm

Re: Constructor Error

Post by XxWalKaxX » November 4th, 2012, 8:51 am

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!

Muttley
Posts: 39
Joined: October 19th, 2012, 6:00 am

Re: Constructor Error

Post by Muttley » November 4th, 2012, 12:51 pm

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.

Post Reply