Emre D
Emre D

Reputation: 1

C++ eror:invalid conversation from 'const char*' to 'int'

I am a beginner. I want use this MoveSkill class with a Crusader object, but I can't do it.

161

class MoveSkill : public Skill {
public:
    int step;   // kaç adım yer değişecek, - ise geriye + ise ileriye
    MoveSkill(int step);

public:
    virtual void Use(std::vector<Unit*> units, int userIndex, int onUsing);
};

596

MoveSkill::MoveSkill(int step) : Skill(std::vector<int>(), std::vector<int>(), "") {
    this->step = step;
}

894

Crusader::Crusader(std::string name) : Hero(33, 5, 0, 1, 0, 3, 6, 12, 67, 40, name) {
    smite = new Smite("Smite");
    stunningBlow = new Stunning_Blow("Stunning Blow");
    holyLance = new Holy_Lance("Holy Lance");
    bulwark = new Bulwark_Of_Faith("Bulwark Of Faith");
    moveskill= new MoveSkill("Move skill");
    skills.push_back(smite);
    skills.push_back(stunningBlow);
    skills.push_back(((AttackSkill*)holyLance));
    skills.push_back(bulwark);
    skills.push_back(moveskill);
}

Build message:

||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\Users\emred\Desktop\project.cpp||In constructor 'Crusader::Crusader(std::__cxx11::string)':|
C:\Users\emred\Desktop\project.cpp|894|error: invalid conversion from 'const char*' to 'int' [-fpermissive]|
C:\Users\emred\Desktop\project.cpp|596|note:   initializing argument 1 of 'MoveSkill::MoveSkill(int)'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

How can I fix it?

Upvotes: 0

Views: 142

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 597051

On this statement:

moveskill= new MoveSkill("Move skill");

The MoveSkill() constructor expects an int as input, but you are giving it a string literal instead (in this case, a const char[11]). So, either give it what it wants, eg:

moveskill= new MoveSkill(12345);

Or else you will have to change the MoveSkill constructor to take a std::string instead of an int.

Upvotes: 2

Related Questions