Header file.
pragma once
class character
{
private:
int m_HP;
int m_MP;
int m_ATK;
int m_Def;
public:
character();
~character();
void setHP(int m_HP);
int hp()
{
return m_HP;
}
void setMP(int m_MP);
int mp()
{
return m_MP;
}
void setatk(int m_ATK);
int atk()
{
return m_ATK;
}
void setdef(int m_Def);
int def()
{
return m_Def;
}
};
It's a cpp
include"character.h"
include"COMMON.h"
character::character()
{
}
character::~character()
{
}
void character::setHP(int hp)
{
m_HP = hp;
}
void character::setMP(int mp)
{
m_MP = mp;
}
void character::setatk(int atk)
{
m_ATK = atk;
}
void character::setdef(int def)
{
m_Def = def;
}
This is the main function
void main()
{
character *player = new character[a];
character *monster = new character[a];
void stat(character *p, int a, int b)
{
The function p->atk = rand() %a + b;//=' was used as the left operand
The function p->def = land() %a;//=' was used as the left operand
The function p->hp = land() %a + b;//=' was used as the left operand
p->mp = land() %b;//"=" function used as left operand "
}
}
There is a c2659 error over there, but I am asking you because I cannot find a solution even if I search and read a book I think it'll be hard to see if I upload it all, so I'm going to skip it If you need it, I'll upload more.
studio
I think you uploaded the main function wrong.
void stat(character *p, int a, int b)
{
The function p->atk = rand() %a + b;//=' was used as the left operand
The function p->def = land() %a;//=' was used as the left operand
The function p->hp = land() %a + b;//=' was used as the left operand
p->mp = land() %b;//"=" function used as left operand "
}
void main()
{
character *player = new character;
character *monster = new character;
int a = 0, b = 1;
stat(player, a, b);
stat(monster, a, b);
//...
}
I think it's the same as above and I'll answer it.
If you look at p->atk = rand() %a + b;
here, you are substituting integers in the member function.
The function cannot be substituted because it is not a variable.
You need to change the expression to substitute for the member variable, but because the member variable is private, you need to change it to use the set**
member function you created.
void stat(character *p, int a, int b)
{
p->setatk(land() %a + b);//=' function used as left operand
p->setdef(land() %a);//=' function used as left operand
p->setHP(land() %a + b);//=' function used as left operand
p->setMP(land() %b);//"=" function used as left operand "
}
© 2024 OneMinuteCode. All rights reserved.