0
C++ Error. A value of "type*" cannot be am entity of type "type*"
As mentioned above, I'm getting this error. I have a class Enemy with the constructor Enemy(int eHP, string eName, int eExp, int eDamage) Then I have another class for a linked list with the node adding function void EnemyList::addEnemy(same as above) Enemy* newEnemy = new Enemy(same as above without variable declarations) if (tailE == NULL) headE = tailE = newEnemy //initialized beforehand The error is here. It tells me what the question title says. Does anyone know how to fix this?
2 ответов
+ 1
From what you show it looks ok. So you don't give enough info to identify the problem explicitly.
All I can think of is: Are headE and tailE and newEnemy all of type Enemy*?
I have a sneaking suspicion your error is something like this:
class A {};
class B : public A {};
This will fail to compile (Implicit 'down-casting' is dangerous; you need an explicit cast for it to work)
// A* a = new A;
// B* b = a;
//This will work (Implicit 'upcasting' is safe)
B* b = new B;
A* a = b;
Can you give more info?
0
Actually you're completely right. The nodes I assigned to the head and tail pointers were of the wrong class. Thanks for helping me out.