#i dont understand what kind of error this is... help
38 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
NPC/npc.cpp: In constructor 'NPC::NPC(const char*, int, int, int)':
NPC/npc.cpp:8:55: error: no matching function for call to 'Stats::Stats(const char*&, int&, int&, int&)'
8 | NPC(const char* name, int hp, int dmg, int def) : stats(name, hp, dmg, def) {}
| ^~~~~~~~~~~~~~~~~~~~~~~~~
Player\player_stats.cpp:3:7: note: candidate: 'constexpr Stats::Stats()'
3 | class Stats{
| ^~~~~
Player\player_stats.cpp:3:7: note: candidate expects 0 arguments, 4 provided
Player\player_stats.cpp:3:7: note: candidate: 'constexpr Stats::Stats(const Stats&)'
Player\player_stats.cpp:3:7: note: candidate expects 1 argument, 4 provided
Player\player_stats.cpp:3:7: note: candidate: 'constexpr Stats::Stats(Stats&&)'
Player\player_stats.cpp:3:7: note: candidate expects 1 argument, 4 provided
this is the error
Send the Stats class
#include <iostream>
#include "npc_stats.cpp"
class NPC{
public:
Stats stats;
NPC(const char* name, int hp, int dmg, int def) : stats(name, hp, dmg, def) {}
};```
```cpp
#include <iostream>
class Stats {
public:
std::string name;
int hp, dmg, def;
Stats(const char* n, int h, int d, int de);
void show_name();
void show_hp();
void show_dmg();
void show_def();
void show_all();
};
Stats::Stats(const char* n, int h, int d, int de) : name(n), hp(h), dmg(d), def(de) {}```
(im new into c++)
There is nothing wrong with what you sent
Show where you're making the NPC that fails
in my "int main(){}" : ```cpp
#include <iostream>
#include "Player\player.cpp"
#include "NPC/npc.cpp"
int main() {
NPC npc1("Mob1", 100, 1, 1);
npc1.stats.show_all();
return 0;
}
you should not include cpp files ever
Only include header files
Declare things in header files and define them in cpp files
Otherwise you will end up with loads of issue
i though including h files is beacuasae of the privacy and in my case i dont need privacy
ohh alr, so this might be the problem
cpp files aren't really anything to do with privacy and more to do with hopw to the compiler and linker work to build a binary
In order to build a binary things need to be defined only once
Yes and then put your function definitions into cpp files or mark them as inline
i ment create a new file with "npc.h" and write all of my function in there*
If you want to put all of your finction in a header file you will need to either mark it inline or define it inside the class
can you give me a example?
You could really do with learning properly how this stuff works
// Stats.h
#pragma once
#include <iostream>
class Stats {
public:
std::string name;
int hp, dmg, def;
Stats(const char* n, int h, int d, int de);
void show_name();
void show_hp();
void show_dmg();
void show_def();
void show_all();
};
// Stats.cpp
#include "Stats.h"
Stats::Stats(const char* n, int h, int d, int de) : name(n), hp(h), dmg(d), def(de) {}
void Stats::show_name() {}
void Stats::show_hp() {}
void Stats::show_dmg() {}
void Stats::show_def() {}
void Stats::show_all() {}
Thats an example with Stats
Follow that pattern for all the other classes
Declerations in the header, definitions in the cpp
Like this?: npc_status.h:
#pragma once
#include <iostream>
class Stats {
public:
std::string name;
int hp, dmg, def;
Stats(const char* n, int h, int d, int de);
void show_name();
void show_hp();
void show_dmg();
void show_def();
void show_all();
};
Stats::Stats(const char* n, int h, int d, int de) : name(n), hp(h), dmg(d), def(de) {}
npc_stats.cpp: ```cpp
// Stats.cpp
#include "npc_stats.h"
Stats::Stats(const char* n, int h, int d, int de) : name(n), hp(h), dmg(d), def(de) {}
void Stats::show_name() {}
void Stats::show_hp() {}
void Stats::show_dmg() {}
void Stats::show_def() {}
void Stats::show_all() {}
and
npc.h```cpp
#pragma once
#include <iostream>
#include "npc_stats.h"
class NPC{
public:
Stats stats;
NPC(const char* name, int hp, int dmg, int def) : stats(name, hp, dmg, def) {}
}; npc.cpp:cpp
#include <iostream>
#include "npc_stats.h"
class NPC{
public:
Stats stats;
NPC(const char* name, int hp, int dmg, int def) : stats(name, hp, dmg, def) {}
};```
i think i dont understand it.. i should watch on youtube or smt for this
!close