#why does my return_dmg functio return 0 when it should return 10?

17 messages · Page 1 of 1 (latest)

proper mica
#

I try to return my items dmg

loud zealotBOT
#

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.

proper mica
#
// mainfile.cpp
#include <iostream>
#include "npc_scripts/npc_list.h"
#include "player_scripts/player.h"
#include "item_scripts/item_list.h"

int main() {
    /*std::string name;

    std::cout << "Enter your Username: ";
    getline(std::cin, name);*/

    Player user("name");

    bool game_running = true;

    while (game_running) {
        int x = sword.return_dmg();
        std::cout << x << std::endl;
        break;
    }

    return 0;
}
#
// items.cpp
#include <iostream>
#include "items.h"

Item::Item(const int id, std::string name, int dmg, int def) {}

int Item::return_dmg() {
    return dmg;
}```
#
// items.h
#include <iostream>

class Item {
private:
    int id, dmg, def;
    std::string name;
public:
    Item(const int id, std::string name, int dmg, int def);
    int return_dmg();
};

#
// item_list.h
#include "items.h"

Item sword(1, "Test", 10, 10);```
#

output: ```cpp
0

west gust
#

it takes arguments, and does nothing with them

proper mica
#

how do i fix it? im new into c++ :l

#

i will look it up on youtube, thank you

#

now i know what is wrong but idk why its wrong xd

west gust
#

the constructor of a class takes some arguments, and uses them to construct the class

#

you need to assign values to the members

loud zealotBOT
#

@proper mica Has your question been resolved? If so, type !solved :)

proper mica
#

!solved