while coding I got the following error: 1>giochino.obj : error LNK2019: riferimento al simbolo esterno "public: void __thiscall entity::print_Pv(int,int)" (?print_Pv@entity@@QAEXHH@Z) non risolto nella funzione _main 1>C:\Users\tomma\source\repos\giochino\Debug\giochino.exe : fatal error LNK1120: 1 esterni non risolti 1>Compilazione progetto "giochino.vcxproj" NON COMPLETATA.
it seems I couldn't find the solution
here's the code, although quite short I can't find the problem
The lib that I've created:
#include <iostream>
using namespace std;
class entity{
public:
int pv_left;
int Max_pv;
//find the percentage of life left and print a bar filled of the same percentage
void print_Pv(int pv_now, int pv_max) {
char pv_bar[10];
int pv_perc = ( pv_now / pv_max) * 10;
for (int i = 0; i < 10; i ) {
if (i <= pv_perc) {
pv_bar[i] = '*';
}
else if (i > pv_perc) {
pv_bar[i] = '°';
}
}
for (int i = 0; i < 10; i ) {
cout << pv_bar[i];
}
}
};
the header of the lib
#pragma once
#include <iostream>
class entity {
public:
int pv_left;
int Max_pv;
void print_Pv(int pv_now, int max_pv);
};
and the main method
#include "game_library.h"
using namespace std;
entity Hero;
int main()
{
Hero.Max_pv = 100;
Hero.pv_left = 10;
Hero.print_Pv(Hero.pv_left, Hero.Max_pv);
}
CodePudding user response:
Your implementation file is wrong, you need
#include "your.h"
void entity::print_Pv(int pv_now, int pv_max) {
char pv_bar[10];
int pv_perc = ( pv_now / pv_max) * 10;
for (int i = 0; i < 10; i ) {
if (i <= pv_perc) {
pv_bar[i] = '*';
}
else if (i > pv_perc) {
pv_bar[i] = '°';
}
}
for (int i = 0; i < 10; i ) {
cout << pv_bar[i];
}
}
you must not declare the class again, just the method bodies that you didnt put in the .h file