Argument Type is incompatible with parameter of same Type

Trying to write a C++ OO code for magic the gathering. And I'm getting an error that I probably am misunderstanding a bit.
k is map<string, Cards*>::iterator for card_dictionary.
and I'm getting the error of Argument of type "Cards*" is incompatible with Parameter of Type "Cards*". Any ideas? Function parameters are fakeDestructor(Cards*).
And card_dictionary is a map<string, Cards>

1
2
3
4
5
  // free card_dictionary
	for (auto k = card_dictionary.begin(); k != card_dictionary.end(); k++)
	{
		player_1->fakeDestructor(k->second);
	}
Last edited on
Argument of type "Cards*" is incompatible with Parameter of Type "Cards*"
Did you mean
Argument of type "Cards" is incompatible with Parameter of Type "Cards*"
?
Next time just copy-paste the error.

What's that snippet supposed to do? Why do you need to call a "fake destructor" when you have normal objects?
@helios nope, the error is copy-pasted.
The "fakeDestructor" is just a name.
The snippet is because I can't post 400 lines of code :)
Last edited on
I do not think it is copy-pasted, because no compiler I know of capitalizes the "Parameter" word in that context.

You don't need to post 400 lines of code, but please copy and post the exact opening of the fakeDestructor function, the declaration of card_dictionary, the declaration of player_1.
Last edited on
If the error is copy-pasted then you're using a compiler I've never seen, and that apparently has a bug because it thinks passing an argument of one type to a parameter of the same type is impossible. Maybe the language is not C++, nor any language I know of. Either way, I can't help you.
Last edited on
E0167 argument of type "Cards *" is incompatible with parameter of type "Cards*"
@helios this is the exact error from the error list. I am using microsoft visual studio 2019.
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
 
     void Player::fakeDestructor(Cards* toDestroy) 
{
	// Free Individual creature
	if (toDestroy->getCardType() == Type_Creature)
	{
		auto mapThing = static_cast<Creature*>(toDestroy); 
		delete mapThing->getAbility(); 
		delete mapThing->getSorcery(); 
		delete mapThing; 
		mapThing = nullptr; 
	}

	// Free Individual Sorcery
	else if (toDestroy->getCardType() == Type_sorcery)
	{
		auto mapThing = static_cast<Sorcery*>(toDestroy); 
		delete mapThing->getActivated();
		delete mapThing; 
		mapThing = nullptr; 
	}
	// Free Enchantments
	else{
		auto mapThing = static_cast<Enchantment*>(toDestroy); 
		delete mapThing; 
		mapThing = nullptr; 
	}
}

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
 
#include "Card_Dictionary.h"


using namespace std; 

map<string, Cards*> cardDict = {
	{Soldier, new Creature{Soldier, "White", Type_Creature, "W", 1, 1} },
{ Armored_Pegasus, new Creature{Armored_Pegasus, "White", Type_Creature,   "1W", 1, 2 }},
	{White_Knight, new Creature{White_Knight, "White", Type_Creature,  "WW", 2, 2, new Ability{ info_FirstStrike}}},
	{AngryBear, new Creature{AngryBear, "Green", Type_Creature,  "2G", 3, 2, new Ability {info_Trample}}},
{Guard, new Creature{ Guard, "White", Type_Creature, "2WW", 2, 5 }},
{Werewolf, new Creature{ Werewolf, "Green", Type_Creature,  "2GW", 4, 6, new Ability{info_Trample}}},
	{Skeleton, new Creature{Skeleton, "Black", Type_Creature,  "B", 1,1}},
	{Ghost, new Creature{Ghost, "Black", Type_Creature,  "1B", 2, 1}},
	{Black_Knight, new Creature{Black_Knight, "Black", Type_Creature,  "BB", 2, 2, new Ability{info_FirstStrike}}},
	{Orc_Maniac, new Creature{Orc_Maniac, "Red", Type_Creature,  "2R", 4, 1}},
	{Hobgoblin, new Creature{Hobgoblin, "Red", Type_Creature,  "1RB", 3, 3}},
	{Vampire, new Creature{Vampire, "Black", Type_Creature,  "3B", 6, 3}},

	{DisEnchant, new Sorcery{DisEnchant, Type_sorcery, "White", "1W", info_DisEnch, new Ability{info_DisEnch}}},
	{L_Bolt, new Sorcery{L_Bolt, Type_sorcery, "Green", "1G", info_LB, new Ability{info_LB}}},
	{Flood, new Sorcery{Flood, Type_sorcery, "Green", "1GW", info_Flood, new Ability{info_Flood}}},
	{ReAnimate, new Sorcery{ReAnimate, Type_sorcery, "Black", "B", info_ReAnimate,  new Ability{info_ReAnimate}}},
	{Plague, new Sorcery{Plague, Type_sorcery, "Black", "2B", info_Plague, new Ability {info_Plague}}},
	{Terror, new Sorcery{Terror, Type_sorcery, "Black", "1B", info_Terror, new Ability{info_Terror}}},

	{Rage, new Enchantment{Rage, Type_enchantment, "Green", "G", info_Rage}},
	{H_War, new Enchantment{H_War, Type_enchantment, "White", "1W", info_HW}},
	{H_Light, new Enchantment{H_Light, Type_enchantment, "White", "1W", info_HL}},
	{Un_War, new Enchantment{Un_War, Type_enchantment, "Black", "1B", info_UHW}},
	{Restrain, new Enchantment{Restrain, Type_enchantment, "Red", "2R", info_Restrain}},
	{Slow, new Enchantment{Slow, Type_enchantment, "Black", "B", info_Slow}}, 




{Forest, new Cards{Forest, Type_Land, "G"}}, 
	{Island, new Cards{Island, Type_Land, "L"}}, 
	{Mountain, new Cards{Mountain, Type_Land, "R"}}, 
	{Plains, new Cards{Plains, Type_Land, "W"}}, 
	{Swamp, new Cards{Swamp, Type_Land, "B"}}

};

1
2
 
Player* player_1 = new Player(names[0], 1); 

That declares and initializes a variable called "cardDict" but I don't know what card_dictionary is.
Okay @Ganado I changed "cardDict" to "card_dictionary" nothing happened.
Could you just put the code up on Github or something? I refuse to accept you're getting that error. Something else is going on.
Are you declaring a variable called "card_dictionary" in more than one place?
Something that would help both you and us, is to construct a minimal, compilable codeset that exhibits the problem.

Chances are that, while trying to do so, you'll discover what the problem is yourself. But if you don't, then at least it will give us something we can compile and investigate ourselves.

Oh, and if changing "cardDict" to "card_dictionary" didn't make any difference, then that can't have been the same thing as the variable called card_dictionary that's in your OP. I'm inclined to agree with Ganado's suggestion - that card_dictionary is already defined somewhere else.

Either that, or the code you're posting here is not the actual code you're trying to compile.
@KareemRj

Has anyone ever mentioned that one should avoid use new and delete ? It looks like you are using new just obtain a pointer.

Consider using references; or a smart pointer like std::unique_ptr<> or std::shared_ptr<> if there is shared ownership instead. I think you code will be much easier to write and understand if you do this. And maybe all your problems will go away.

Are you aware that STL containers already put their objects in dynamic memory, so there is no need for you to do dynamic memory yourself ?
I'd love to see the rest of the code. I've played around with some theories I have about what is happening. I see a couple different objects being created all returning the same type supposedly. I think there's a much deeper issue here than a function parameter type.
It may help if you posted the definition of Cards, Creature, Sorcery and Enchantment.

You're only going to get speculation if we can't see what type your things are.

For example, if Cards was a base class of Creature, Sorcery and Enchantment, and Cards had a virtual destructor, you wouldn't need all those shenanigans in fakeDestructor(). And it would also explain the initialization of cardDict.
Topic archived. No new replies allowed.