Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / I get a "no appropriate default constructor available" for my file.cpp

Author
Message
yahya
15
Years of Service
User Offline
Joined: 16th Oct 2008
Location:
Posted: 29th Jun 2009 20:22 Edited at: 29th Jun 2009 20:26
I keep getting this :S

shhoting.h


Shootin.cpp



then I geth is " error C2512: 'Shooting_Bullets' : no appropriate default constructor available"

for this

"Shooting_Bullets Bullet[MaxBullets]; // Makes the actual bullet array"
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 29th Jun 2009 20:30 Edited at: 29th Jun 2009 20:32
You have this constructor defined:

Shooting_Bullets(int objID, char* BulletName);

what you don't have is a simple:

Shooting_Bullets (void);

constructor defined. I'm assuming that somewhere you're declaring

Shooting_Bullets Bullet [MaxBullets];

This will require a default constructor. Depending on what else you may be doing you may also need a copy constructor.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
yahya
15
Years of Service
User Offline
Joined: 16th Oct 2008
Location:
Posted: 30th Jun 2009 02:39
So you want me to add "Shooting_Bullets (void);" under "Shooting_Bullets Bullet [MaxBullets];"?

I already did:
Shooting_Bullets(int objID, char* BulletName);
~Shooting_Bullets();
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 30th Jun 2009 03:23
No, she told you to add a default constructor inside your class in addition to the other one.


Then define it in the .cpp file like this:

Shooting_Bullets::Shooting_Bullets(void) { }


She also said that you may need a copy constructor, which would be defined in you class as something like this:

Shooting_Bullets(const Shooting_Bullets& copy);


And define it like this in the .cpp file:

Shooting_Bullets::Shooting_Bullets(const Shooting_Bullets& copy) {
this.BulletID = copy.BulletID;
this.Exist = copy.Exist;
// etc...
}

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
yahya
15
Years of Service
User Offline
Joined: 16th Oct 2008
Location:
Posted: 30th Jun 2009 10:46 Edited at: 30th Jun 2009 10:52
Will problem is almost resolved , weird, I didn't ask me any of this for my other classes.


First I think you meant for the to be like this:




second:

anyway when I just put the " Shooting_Bullets(void); // Default constructor" it goes :



Am guessing it has a problem with "Shooting_Bullets Bullet[MaxBullets];" since I moved it in the .cpp file, to resolve some problems, like :



so now the .cpp looks like this:



The problem is, I don't get what the compiler wants or doesn't like :S.
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 30th Jun 2009 18:03 Edited at: 30th Jun 2009 18:03
Yes, sometimes I forget to use '->' instead of '.' when I'm not using visual studio to guide me . It doesn't matter where you put the 'Shooting_Bullets Bullet[MaxBullets]'. Your problem is that you still didn't define the default constructor. You can either put brackets after the name instead of the semicolon in the .h file, or you can put it in the .cpp file.




PS - Don't forget to finish that copy constructor by copying all values necessary from the copy to the pointer to the class object (this).

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
yahya
15
Years of Service
User Offline
Joined: 16th Oct 2008
Location:
Posted: 30th Jun 2009 20:12
WOW I actaully forgot to put something like that :S, I was too concentrated on the array I didn't notice I didn't the rest of the default constructor ion the .cpp file.

Will it runs now, and am still working on the copy constructor, but am trying to make this class actually shoot bullets first.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 30th Jun 2009 20:50
Bear in mind that when you declare an array of class object the default constructor is run on each of the elements. IMS, you can also run a parameterized constructor but you can't individualize things like variable numberical data at the time of declaration. Yes, there's a workaround using a static counter but that's getting too deeply into it.

AAR, if you try something like Bullets[index] = myBullet you need a copy constructor to make sure that all the data is copied properly. Supposedly it will to a byte-wise copy of the data without a copy constructor but this is dangerous, especially if the data includes pointers to dynamically allocated memory.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
yahya
15
Years of Service
User Offline
Joined: 16th Oct 2008
Location:
Posted: 30th Jun 2009 23:35
OK one last thing, but its not a error or anything, I just need to know one last thing and am good to go, plz pare with me .

I got it working and all, but the bullet spheres are colliding with my "universe.dbo", I guess hes reading it as an object :S, how can I say collide with everything else but "universe.dbo", I know this has nothing to do with the topic, but am really close to my gaol, and it would be unnecessary to make a new topic for just this.
yahya
15
Years of Service
User Offline
Joined: 16th Oct 2008
Location:
Posted: 1st Jul 2009 12:02 Edited at: 1st Jul 2009 14:45
anyone?



Edit:nvm I'll create a new topic

Login to post a reply

Server time is: 2024-10-01 05:47:49
Your offset time is: 2024-10-01 05:47:49