Sign in to follow this  
Evil Booger

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

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[i].laser_speed_regulator == Inactive && EnemyShipArray[i].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
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[i].laser_speed_regulator == Inactive && EnemyShipArray[i].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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this