#i dont understand what kind of error this is... help

38 messages · Page 1 of 1 (latest)

odd hatch
#

im trying to add a mob in my textadvature and i cant make one.

near auroraBOT
#

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.

odd hatch
#
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

somber cloak
#

Send the Stats class

odd hatch
#
#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++)

somber cloak
#

There is nothing wrong with what you sent

#

Show where you're making the NPC that fails

odd hatch
#

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;

}

somber cloak
#

Only include header files

#

Declare things in header files and define them in cpp files

#

Otherwise you will end up with loads of issue

odd hatch
#

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

somber cloak
#

In order to build a binary things need to be defined only once

odd hatch
#

so do i need to make all of my files (not the main file) to a .h?

somber cloak
odd hatch
#

i ment create a new file with "npc.h" and write all of my function in there*

somber cloak
odd hatch
#

can you give me a example?

somber cloak
#

You could really do with learning properly how this stuff works

odd hatch
#

thats new for me

#

xd

#

or like a video for it

somber cloak
#
// 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

odd hatch
#

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