[SOLVED] My code is broken

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
jaybee
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 27
Joined: Thu Jan 13, 2011 12:53 pm
Current Project: 2d platformer
Favorite Gaming Platforms: NES, SNES, Genesis, DOS
Programming Language of Choice: C++
Location: Running Springs, CA

[SOLVED] My code is broken

Post by jaybee »

Hey guys. So after a brief hiatus I've started working on my shoot em up once again. Once I started digging around in the code I realized I was going to have to restructure things quite a bit. What I'm working on right now is a ship manager class that will take care of drawing the player and enemy ships and what not. So anyways it works fine as far as the enemies are concerned and does what it supposed to do there, but, I can't get it to instantiate a player.

I'm sure I'm missing something totally trivial and easy here but I've been up extremely late the past few nights trying to get this all working and I can't for the life of me find the problem. heres what I'm trying to do:

Code: Select all

class ShipManager
{
     ....


public:
    Character player;

};
When I add the player object to the header code::blocks points at the constructor for my ShipManager class and spits out the following errors.

error: no matching function for call to 'Character::Character()'
note: candidates are: Character::Character(int, int, int, int, int, float, float, float)
note: Character::Character(const Character&)


I'm a little cracked out on my own code right now and I'm sure this is something simple but I just can't find it. Any clues? I can post any other code that may be applicable after I get off work.
Last edited by jaybee on Thu Mar 31, 2011 2:00 pm, edited 1 time in total.
"Do I really have to spell this out? What if a bunch of punk kids go into the woods with a bullet proof vest and strap it on a grizzly bear? Then what have you got? Invincible bears. Is that what you want? Invincible bears running around; raping your churches and burning your women?"
User avatar
adikid89
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 94
Joined: Tue Apr 27, 2010 6:59 am
Current Project: small tiny-mini projects
Favorite Gaming Platforms: PC I guess...
Programming Language of Choice: c++

Re: My code is broken

Post by adikid89 »

It's because of Character player; when you do that.. it'll call the Character() constructor.. the one with no parameters.. which you don't have.
What you can do is... in the initializer list initialize the player with the appropriate constructor, like so:

Code: Select all

ShipManager(): player(0,0,0,0,0.f,0.f) {}
Or make the player a pointer.. as such: Character* player; And you just new it when you need it with the appropriate constructor like this:

Code: Select all

player = new Character(0,0,0,0,0.f,0.f); 
. Just remember to free it when you're done.. like in the destructor or somewhere.
My first game C++/SDL Yoshi Combat! = http://www.youtube.com/watch?v=HQ9mMBEWSZg
==============================================================
Image
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: My code is broken

Post by dandymcgee »

jaybee wrote: When I add the player object to the header code::blocks points at the constructor for my ShipManager class and spits out the following errors.

error: no matching function for call to 'Character::Character()'
note: candidates are: Character::Character(int, int, int, int, int, float, float, float)
note: Character::Character(const Character&)
You overloaded the default constructor in your Character class to take 5 ints and 3 floats, so there is no longer a constructor which takes 0 arguments. This causes a line such as the following to fail:

Code: Select all

Character bob;
as well as

Code: Select all

Character* bob = new Character();
You either need to provide those arguments where you are constructing the object, or add a constructor that handles 0 arguments to your Character class:

Code: Select all

Character::Character();
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
jaybee
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 27
Joined: Thu Jan 13, 2011 12:53 pm
Current Project: 2d platformer
Favorite Gaming Platforms: NES, SNES, Genesis, DOS
Programming Language of Choice: C++
Location: Running Springs, CA

Re: My code is broken

Post by jaybee »

Ohhhh right thank you. Not sure how I missed that one. I've been kinda rewriting my code from the inside out and my brain is basically jello at this point. But hey I'm learning a lot in the process. Anyways thank you I really appreciate it.
Post Reply