Thread: Question about classes

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    6

    Question about classes

    I'm trying to write a clone of Galaga using the allegro library and have been using classes. I have a class called enemy and I'm wondering why this isn't a valid call to the destructor
    Code:
    class Enemy {
    	int health;
    	
    public:
    	int x_position;
    	int y_position;
    	bool collision;
    	BITMAP *image;
    
    	//constructor
    	Enemy(int x, int y,int h = 1){
    	x_position = x;
    	y_position = y;
    	health = h;
    	bool collision=false;
    	
    	image = load_bitmap("enemyShip.bmp", NULL);
    }
    	//destructor
    	~Enemy(){destroy_bitmap(image);}
    
    	//class functions
    	int get_health(){return health;}
    	void movement(int&x,int&y);
    	
    };
    then I have the function definiton for movement here

    Code:
    void Enemy::movement(int &x, int &y)
    {
    	while(collision==false)
    	{
    		//try to add support for sin movement across screen
    	}
    	if (collision==true){~Enemy();}
    }

    is it not valid to call the destructor inside a class function?

    this is the compiling error

    error C2512: 'Enemy::Enemy' : no appropriate default constructor available

    I'm figuring this means that it's thinking I'm trying to call a constructor? If so, am I mistaken that the ~Enemy() call isn't a destructor, I was under the impression that it was.

    Sorry if this is a stupid question.
    Thanks for the Help,
    mjhamrick
    Last edited by mjhamrick; 06-26-2010 at 07:47 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes question...
    By Raigne in forum C++ Programming
    Replies: 24
    Last Post: 09-12-2006, 01:46 AM
  2. Replies: 2
    Last Post: 07-28-2006, 02:59 PM
  3. Simple Question about Classes
    By Loctan in forum C++ Programming
    Replies: 5
    Last Post: 06-26-2006, 02:40 AM
  4. Classes and Win32 API, and another Question
    By philvaira in forum Windows Programming
    Replies: 10
    Last Post: 04-10-2004, 07:21 PM
  5. Newbie question about the Private type in classes
    By Ryeguy457 in forum C++ Programming
    Replies: 1
    Last Post: 09-07-2002, 10:17 PM

Tags for this Thread