problem z odwolaniem do klasy

0
#include <iostream>
#include <cmath>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstdio>
#include<conio.h>

using namespace std;



int losowanie(int a){
    srand(time(NULL));
    return rand()%a;
}





void tekst(string a, int b){
for(int i=0;i<a.length();i++){
    cout<<a[i];_sleep(b);
}
}

class item
{

    int item_ID;
    string item_name;
    int item_weight;
    friend class backpack;
    public :

    item(int item_ID,int item_weight,string item_name)
    {
        this->item_ID = item_ID;
        this->item_weight = item_weight;
        this->item_name = item_name;




    }


    int get_weight()
    {
        return item_weight;
    }

    string get_name()
    {
        return item_name;

    }
    int get_id()
    {
        return item_ID;
    }

    void set_id(int id)
    {
        item_ID=id;
    }

    void set_weight(int a)
    {
        item_weight = a;
    }

    void set_name(string a)
    {
        item_name = a;
    }

};



class backpack
: public item
{

    item slot[100];
    int max_weight;
    int current_weight;

public :
   void item_add(item stuff)
    {

        item *marker;
        marker = &slot[0];

        int loop=1;

        while (loop==1)

        {
            if (*marker.get_id()==NULL)
            {
                if ((current_weight+item :: stuff.get_weight())>max_weight)
                {
                string imie; //ten string jest definiowany w mainie i tylko podmieniana jest zawartosc;
                cout<<endl;
                cout<<imie<<endl;
                string talk;
                talk = "Nie dam rady tyle podniesc";
                tekst(talk,60);
                loop=0;
                }
                else
                {
                    item::*marker.set_id(item ::stuff.get_id());
                   item:: *marker.set_weight(item :: stuff.get_weight());
                    item:: *marker.set_name(item ::stuff.get_name());
                    loop=0;
                }

            }
            else
                marker++;
            }


        }









};


class person
{
    backpack plecak;
    string person_name;
    person(string person_name)
    {


    this->person_name = person_name;

    }
    void item_add(item stuff)
    {

        plecak.item_add(stuff);

    }


};
main ()
{
    item mieczyk(1,2,"mieczyk");
    person krystian("krystian nie umie programowac");
    krystian.item_add(mieczyk);
    
    
    
    
}

Witam, program wywala blą w linijce class backpack no matching function for call to class.

Dla wszelkiej pewności osób zaawansowanych jak widać mój staż w programowaniu jest ekhm... dość krótki :)

Proszę o wyjaśnienie co zrobiłem źle.

0
  1. Nie wiem czy friendowanie między klasami to dobry pomysł, lepiej zmień modyfikator dostępu w klasie item z private na protected; Z drugiej strony to nie wiem jaki jest logiczny sens dziedziczenia bacpacka po itemie?
  2. Czemu w klasie item_add używasz modyfikatora ::? zapomniałem jak to się nazywa ale używasz tego do pobrania zmiennych statycznych klasy a żadnych nie zauważyłem.
  3. Zamiast próbować wypisywać info że nie da rady tyle podnieść w item_add można zrobić tak że funkcja zwraca false lub true w zależności od tego czy waga maksymalna nie została przekroczona i dopiero na tej podstawie niech se ludzik gada że nie da rady tyle unieść.

Przerobiłem żeby chociaż zadziałało, ale wiele można by jeszcze poprawić:

 #include <iostream>
#include <cmath>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstdio>
#include <conio.h>
#include <string>
 
using namespace std;
 
int losowanie(int a)
{
    srand(time(NULL));
    return rand()%a;
}
 
void tekst(string a, int b)
{
	for(int i = 0; i < a.length(); i++)
	{
		cout<<a[i];
		_sleep(b);
	}
}
 
class item
{
protected:
    int item_ID;
    string item_name;
    int item_weight;

public : 
    item(int item_ID = 0, int item_weight = 0, string item_name = "")
    {
        this->item_ID = item_ID;
        this->item_weight = item_weight;
        this->item_name = item_name; 
    }
 
    int get_weight()
    {
        return item_weight;
    }
 
    string get_name()
    {
        return item_name;
 
    }
    int get_id()
    {
        return item_ID;
    }
 
    void set_id(int id)
    {
        item_ID = id;
    }
 
    void set_weight(int a)
    {
        item_weight = a;
    }
 
    void set_name(string a)
    {
        item_name = a;
    }
 
};
 
class backpack
{ 
    item slot[100];
    int max_weight;
    int current_weight;
	int item_count;
 
public :
	backpack()
	{
		item_count = 0;
	}

	bool item_add(item stuff)
    { 
        if ((current_weight + stuff.get_weight()) > max_weight)
        {
			return false;
        }
        else
        {
            slot[item_count].set_id(stuff.get_id());
			slot[item_count].set_weight(stuff.get_weight());
            slot[item_count].set_name(stuff.get_name());
			item_count++;
        }
    } 
};
 
class person
{
    backpack plecak;
    string person_name;
public:
    person(string person_name)
    { 
		this->person_name = person_name; 
    }
    void item_add(item stuff)
    { 
        if (!plecak.item_add(stuff))
		{
			cout << person_name << ": nie dam rady tyle uniesc\n";
		}
    } 
};

main ()
{
	item mieczyk(1, 2, "mieczyk");
    person krystian("krystian nie umie programowac");
    krystian.item_add(mieczyk); 
}
0
#include <iostream>
#include <cmath>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstdio>
#include <conio.h>
#include <string>

using namespace std;

int losowanie(int a)
{
    srand(time(NULL));
    return rand()%a;
}

void tekst(string a, int b)
{
    for(int i = 0; i < a.length(); i++)
    {
        cout<<a[i];
        _sleep(b);
    }
}

class item
{
protected:
    int item_ID;
    string item_name;
    int item_weight;

public :
    item(int item_ID = 0, int item_weight = 0, string item_name = "")
    {
        this->item_ID = item_ID;
        this->item_weight = item_weight;
        this->item_name = item_name;
    }

    int get_weight()
    {
        return item_weight;
    }

    string get_name()
    {
        return item_name;

    }
    int get_id()
    {
        return item_ID;
    }

    void set_id(int id)
    {
        item_ID = id;
    }

    void set_weight(int a)
    {
        item_weight = a;
    }

    void set_name(string a)
    {
        item_name = a;
    }

};

class backpack
{
    item slot[100];
    int max_weight;
    int current_weight;
    int item_count;

public :
    backpack(int max_weight = 100, int current_weight =0)
    {
        item_count = 0;
        this ->max_weight = max_weight;
        this ->current_weight = current_weight ;
    }

    bool item_add(item stuff)
    {
        if ((current_weight + stuff.get_weight()) > max_weight)
        {
            return false;
        }
        else
        {
            slot[item_count].set_id(stuff.get_id());
            slot[item_count].set_weight(stuff.get_weight());
            slot[item_count].set_name(stuff.get_name());
            item_count++;
        }
    }
};

class person
{
    backpack plecak;
    string person_name;
public:
    person(string person_name) :plecak()
    {
        this->person_name = person_name;
    }
    void item_add(item stuff)
    {
        if (!plecak.item_add(stuff))
        {
            cout << person_name << ": nie dam rady tyle uniesc\n";
        }
        else

            cout<<"elo elo 320";
    }
};

main ()
{
    item mieczyk(1, 2, "mieczyk");
    person krystian("krystian nie umie programowac");
    krystian.item_add(mieczyk);
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1