Not a Type Name

"Sorcery*" and "<Enchantemnt*>" is not type name. Believe it or not, did NOT have this error yesterday. I don't know what happened. But I didn't change anything in the code. I saved it and returned to it today.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <vector>
#include <string> 
#include <memory>
#include "CardAbilitiesAndEffects.h"
#include "Cards.h"
#include "Player.h"
#include "Sorcery.h"
#include "Enchantment.h"


using namespace std; 

class Creature : public Cards
{

protected: 
	
	int AttackPower; 
	int HP; 
	CardAbilitiesAndEffects* Trigger; 
	Sorcery* Sorcerized; 
	vector<Enchantment*> enchantment; 
               //Not a Type Name
public: 
	Creature(string name, string Type, string manacost, int attack, CardAbilitiesAndEffects* ability, Sorcery* sorcerized); 
	Creature(string name, string Type, string manacost, int attack, CardAbilitiesAndEffects* ability); 
	Creature(string name, string Type, string manacost, int attack, Sorcery* sorcerized);                                                             //Not a Type Name
	Creature(string name, string Type, string manacost, int attack); 
	Creature(Creature* other);
	virtual ~Creature(); 
	void clearEnchantments(); 
	CardAbilitiesAndEffects& getAbility(); 
	Sorcery& getReallySorcerized(); 
         //Not a Type Name
	void setAbility(CardAbilitiesAndEffects* ptr);
	void setSorcery(Sorcery* ptr); 
	CardAbilitiesAndEffects* AbilityUsed(); 
	Sorcery* GetSorcerized(); 
         //Not a Type Name
	void attackPlayer(Player* player); 
	bool attackCreature(Player* opponent, int Creature2Attack); 
	bool ChangeHP(int newHP); 
	int GetHP();
	int GetAP(int ap); 
	void printEnchantments(); 
	bool addEnchantment(int pos, Player* p, int Target); 
	void removeEnchantment(); 
	vector<string> displayCard(); 
	void useCardonCard(Player* Attacker, Player* Attacked, int pos); 
	
};

Possible fix is to add:
1
2
class Sorcery;
class Enchantment;
before your Creature class definition.

If you are only using a pointer in the header, then you don't need to #include the corresponding header; only a forward declaration is needed. (You'd need to #include the necessary files to actually use the object that is being pointed to within the .cpp file)
Last edited on
@Ganando

I just tried it, it didn't work..
and even in the cpp file it's not working..
> #include "Sorcery.h"
> #include "Enchantment.h"
So what's in these files then?

> using namespace std;
Using this at all is generally evil.
Using it in a header file is especially evil.
https://stackoverflow.com/questions/5849457/using-namespace-in-c-headers

> But I didn't change anything in the code. I saved it and returned to it today.
https://en.wikipedia.org/wiki/Comparison_of_version-control_software
Once you get past the student homework "single file, single edit" stage, you're going to be writing multiple source files over a period of time.
Get into the habit of "checking in" your work, ideally after every successful "compile and test".
For example, the simple ability to do a "diff" between the last known good version and your latest edit will save you no end of time in the long run.
> it didn't work
Okay, but how does it not work now? Is there now a different error message? (And as salem c says, we'd have a more complete picture of the problem by seeing what is in Sorcery.h and Enchantment.h, as these are the classes you're having problems with.)
Yeah I closed the topic because I did something stupid by making strings with the same name so the compiler lost it lol. That's why I marked it as solved :D and adding the other header files is really not the way to go since I have 7 .h files :D
Last edited on
adding the other header files is really not the way to go since I have 7 .h files

Gosh, I have just over 200 ...

Version control is awesome, like salem c says.
+1 to @keskiverto.

If you think 7 header files is a lot, you have a lot to learn.

You should include exactly as many header files as you need. No more--no less. You should include headers in either the header or the source file--exactly where you need it, not just everywhere.

One strategy new programmers sometimes use is to create a huge mother-of-all-headers file that includes all of the headers in the project. Then, the source files only need to include this 1 file. DON'T FALL INTO THIS TRAP!!! When you start working on large projects (1000s of source files), massive ultra-include files will slow down your rebuilds. A rebuild that should take 10 minutes will end up taking hours.

The best answer is to get used to including each of the header files you need, individually, into your source files.

BTW, @Ganado's comment is worth looking into. Because you only use Sorcery* and Enchantment* in your header file, forward declarations are probably all that is needed here. Make sure you include the proper header files in the source file (presumably Creature.cpp), but the header doesn't need them.

Yeah, get to know how to use forward declarations. They can really help speed up builds in large projects.
Last edited on
Topic archived. No new replies allowed.