Jump to content


Problem with C++ tutorial part 12: Classes


2 replies to this topic

#1 Rimevan

    Member

  • Members
  • PipPip
  • 11 posts

Posted 15 February 2012 - 03:59 PM

I've been following the tutorials and there weren't any problems until part 9 and 12. I am still struggling with part 9, but
part 12 is something I think I am not able to solve. My code was this:
// Template, major revision 3
// IGAD/NHTV - Jacco Bikker - 2006-2009

#include "string.h"
#include "surface.h"
#include "stdlib.h"
#include "template.h"
#include "game.h"

using namespace Tmpl8;

class Tank
{
public:
	Tank()
	{
		x = 0;
		y = 4 * 64;
		rotation = 0;
	}
	void Move( Surface* a_Screen)
	{
		x++;
		if ( x > ( 16 * 64 ) ) x = 0;
   	 tank.Draw( x, y, a_Screen );
	}
	int x, y, rotation;
};

Tank mytank;
					  
void Game::Init()
{

}

void Game::Tick( float a_DT )
{
	mytank.Move( m_Screen );
}


The errors I got:
1>c:\-\part12\game.cpp(25) : error C2065: 'tank' : undeclared identifier
1>c:\-\part12\game.cpp(25) : error C2228: left of '.Draw' must have class/struct/union


I thought it was weird, since this is exactly what was written in the tutorial. Luckily, I thought I understood the problem, so I
changed 'tank.Draw' to 'Tank.Draw'. Unfortunately, this gave me these errors (both the same?):
1>c:\-\part12\game.cpp(25) : error C2143: syntax error : missing ';' before '.'
1>c:\-\part12\game.cpp(25) : error C2143: syntax error : missing ';' before '.'


This is where I got stuck..does anyone know how to solve this problem?

Rimevan

#2 jari

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 15 February 2012 - 11:19 PM

I can't find the source code for Part 12, but seeing the others, the "tank" from the line "tank.Draw( x, y, a_Screen );" is a Sprite object, not the Tank class' instance. The Sprite object is the "image" what you draw to the screen. Don't you miss a line like this "Sprite theSprite( new Surface("assets/ctankbase.tga"), 16 );" somewhere?

#3 Rimevan

    Member

  • Members
  • PipPip
  • 11 posts

Posted 16 February 2012 - 02:18 PM

 jari, on 15 February 2012 - 11:19 PM, said:

I can't find the source code for Part 12, but seeing the others, the "tank" from the line "tank.Draw( x, y, a_Screen );" is a Sprite object, not the Tank class' instance. The Sprite object is the "image" what you draw to the screen. Don't you miss a line like this "Sprite theSprite( new Surface("assets/ctankbase.tga"), 16 );" somewhere?

Ah, that's quite obvious=/ Thanks for the help, putting
Sprite tank( new Surface("assets/ctankbase.tga"), 16 );
just above the Tank class solved the problem.

Rimevan





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users