Advertisement Jump to content
Sign in to follow this  
Taint

Multiple types in declaration?

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

I'm getting an error saying "multiple types in declaration" when I try to compile my main cpp file, but I'm pretty sure the error is coming from my "cEnemy.hpp" header file. I've searched the internet and all I can find is people saying to make sure to include the ; at the end of the class declaration, which I've done. I'm sure it's just something stupid I should have noticed. What have I done wrong?

 

cEnemy.hpp:

#include <string>

enum ENEMY_TYPE { ZOMBIE, RAT, ORC, BANDIT, DOG } 

class cEnemy
{
	public:
		cEnemy(int h, ENEMY_TYPE t) { setHealth(h); setType(t); }
		~cEnemy() {}
		inline int getHealth() const { return health; }
		inline void setHealth(int h) { health = h; }
		inline void takeDmg(int d) { health = (health - d); }
		inline void setType(ENEMY_TYPE t) { type = t; }
		inline std::string getType() const
		{
			switch(type)
			{
				case ZOMBIE:
					return "Zombie";
					break;
				case RAT:
					return "Rat";
					break;
				case ORC:
					return "Orc";
					break;
				case BANDIT:
					return "Bandit";
					break;
				case DOG:
					return "Wild Dog";
					break;
				default:
					return "Error";
					break;
									
			}
				
		}
	private:
		int health;
		ENEMY_TYPE type;
};

main.cpp:

#include "enemy.hpp"
#include "rand.hpp"
#include <iostream>

enum ERR_CODE { SUCCESS, ERROR };

ERR_CODE fight(cEnemy *a, cEnemy *b)
{
	short aDmg, bDmg;
	while(true)
	{
		if(a->getHealth() <= 0 || b->getHealth() <= 0)
		{
			break;
		}
		else
		{
			
			bDmg = genRandom(1,10);
			b->takeDmg(bDmg);
			std::cout << std::endl;
			std::cout << a->getType() << "attacked Robot 2 for " << bDmg << "." << std::endl << std::endl;
			if(b->getHealth() < 0) { b->setHealth(0); }
			std::cout << "Robot 1 health: " << a->getHealth() << "\tRobot 2 health: " << b->getHealth() << std::endl;
			std::cin.get();
		}
		
		if(a->getHealth() <= 0 || b->getHealth() <= 0)
		{
			break;
		}
		else
		{
			aDmg = genRandom(1,10);
			a->takeDmg(aDmg);
			std::cout << std::endl;
			std::cout << "Robot 2 attacked Robot 1 for " << aDmg << "." << std::endl << std::endl;
			if(a->getHealth() < 0) { a->setHealth(0); }
			std::cout << "Robot 1 health: " << a->getHealth() << "\tRobot 2 health: " << b->getHealth() << std::endl;
			std::cin.get();
		}
	}
	
	return SUCCESS;
}
	

int main()
{
	cEnemy enemy1(40, BANDIT);
	cEnemy enemy2(50, ORC);
	
	fight(&enemy1, &enemy2);
	
	
	if(enemy1.getHealth() <= 0)
	{
		std::cout << "Robot 2 Wins." << std::endl;
	}
	else
	{
		std::cout << "Robot 1 Wins." << std::endl;
	}
		
	return 0;
}

The main code might not make a lot of sense because it was originally a (working) program with robots, not enemies of different types.

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net 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!