Obiekty jako składowe klasy.

0

Witam mam problem z dodaniem obiektu do zmiennych klasy. Straciłem nadzieję że zrobię to sam, proszę o pomoc.

Program pisany w C++ oczywiście.

########################################
#ifndef ITEM_H
#define ITEM_H
#include <string>
using namespace std;

/*
 * No description
 */
class Item
{
protected: 
	string nazwa;
public:
	Item(string nazwa);

};

#endif // ITEM_H
#############################################
#include "stdafx.h"
#include "item.h" // class's header file
#include <string>
using namespace std;

Item::Item(string nazwa)
{

	this->nazwa=nazwa;

}
###########################################
#ifndef WEAPON_H
#define WEAPON_H

#include <string>
#include "item.h"
using namespace std;


class Weapon:public Item
{

protected: 
	int obrazenia;
public:
	Weapon(int obrazenia);

};
#endif // WEAPON_H
##################################################
#include "stdafx.h"
#include "weapon.h" // class's header file
#include <string>
using namespace std;


Weapon::Weapon(int obrazenia):Item(nazwa)
{
	this->obrazenia=obrazenia;
}

########################################################

 
#ifndef postac
#define postac

#include "stdafx.h"
#include <string>
#include "string.h"
#include "weapon.h"

class Postac
{
protected:
	Weapon miecz;
	unsigned int id;
	string name;

public:

Postac (unsigned int id, string name, string nazwa, int obrazenia);

};
#endif postac

################################################

 
#include "stdafx.h"
#include "postac.h"
#include <string>

using namespace std;

Postac::Postac(unsigned int id, string name, string nazwa, int obrazenia):Weapon(obrazenia),Item(nazwa)
{
	this->id=id;
	this->name=name;
}

błędy:
Error 1 error C2512: 'Weapon' : no appropriate default constructor available c:\users\boorisho\desktop\skladowe\skladowe\postac.cpp 10

3	IntelliSense: "Item" is not a nonstatic data member or base class of class "Postac"	c:\users\boorisho\desktop\skladowe\skladowe\postac.cpp	9

2	IntelliSense: "Weapon" is not a nonstatic data member or base class of class "Postac"	c:\users\boorisho\desktop\skladowe\skladowe\postac.cpp	9

4	IntelliSense: no default constructor exists for class "Weapon"	c:\users\boorisho\desktop\skladowe\skladowe\postac.cpp	10
0
boorisho napisał(a):
Postac::Postac(unsigned int id, string name, string nazwa, int obrazenia):Weapon(obrazenia),Item(nazwa)

zmień tą linijkę na

Postac::Postac(unsigned int id, string name, string nazwa, int obrazenia):miecz(obrazenia)

Pytanie,cóż to ma być Item(nazwa)?Nigdzie w klasie nie widzę nic coby pasowało do tej deklaracji.

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