Advertisement Jump to content
Sign in to follow this  

const init within a class

This topic is 4765 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

MSVC8 express wont let me compile with the constant, BALL_VELOCITY outside of the initializer list(like below). Is it something im doing wrong, or this a rule? Ball::Ball(int bv)
	pBallBitmap = SDL_LoadBMP("ball.bmp");
	SDL_SetColorKey(pBallBitmap, SDL_SRCCOLORKEY, SDL_MapRGB(pBallBitmap->format, 255,0,255));

	mBallRect;                       //rect for bitmap position info
	mBallRect.x = 6;
	mBallRect.y = 6;
	mBallRect.w = 14;
	mBallRect.h = 14;
	mpBallRect = &mBallRect;         //pointer to ballrect

	BALLx = 300;
	BALLy = 400;
	BALL_VELOCITYx = bv; // or BALL_VELOCITYx = 500; ?
	BALL_VELOCITYy = bv; // or BALL_VELOCITYy = 500; ?
	ballVelx = 0;
	ballVely = -1;

Share this post

Link to post
Share on other sites
It's a rule; non-static constant members must be initialized in the member initialization list.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!