Jump to content
  • Advertisement
Sign in to follow this  
Evil Booger

Having troubles/errors with classes in classes and inheritance and const ints

This topic is 4057 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok I have an inherited class named EnemyShip:
…
…
class EnemyShip: public Ship
{
public:
	Wait laserwait(LASER_RELOAD_SPEED);//Line 648
	Wait missilewait(MISSILE_RELOAD_SPEED);
…
…
…
and I when I compile, I get the error messages: …main.h(648) : error C2061: syntax error : identifier 'LASER_RELOAD_SPEED' …main.h(649) : error C2061: syntax error : identifier 'MISSILE_RELOAD_SPEED' Even though I clearly define those const int’s at the top of the page
const int LASER_RELOAD_SPEED = 200; //1000 = 1 second
const int MISSILE_RELOAD_SPEED = 300; //1000 = 1 second
and I get another error message: …level.h(99) : error C2228: left of '.Done' must have class/struct/union
…
…
if (EnemyShipArray.laser_speed_regulator == Inactive && EnemyShipArray.laserwait.Done()) //Line 99
{
…
…
Where “i” is an int bwtween 0 and 15 in a for loop. I don’t understand how such clearly defined items can be error messaged (woo just made that up). This is bothering me more than it should, as in I shouldn't be up at 2am on a school night working on a space shooter. Thank you so much in advance for helping me. Tell me if you need more code.

Share this post


Link to post
Share on other sites
Advertisement
Okay, here goes.

1. You're using constants in function declarations
I'm not really sure what you're trying to do here. If you have two different functions, there's not really any need to have two different wait values. Conversely, if you only have one wait function (weapon_wait(), for example), then you can pass it many different values. LASER_RELOAD_SPEED is basically the number 200, which means you're writing "Wait laserwait(200);". That's how you call functions, not declare them.


2. You've just missed some parenthesis -> ()
Change that line to if (EnemyShipArray.laser_speed_regulator == Inactive && EnemyShipArray.laserwait().Done()), and you should be set.



Come back to us if you have any more problems.

Share this post


Link to post
Share on other sites
In C++, initialization of member variables is done in the initialization lists. In short:

class EnemyShip: public Ship
{
public:
Wait laserwait;
Wait missilewait;

EnemyShip() :
laserwait(LASER_RELOAD_SPEED),
missilewait(MISSILE_RELOAD_SPEED)
{}
};

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!