- Я новичок в C++. Компилятор жалуется на строку ниже: inv.inventory [0] = «Книги». Помогите мне, как я могу присвоить значения статическому массиву в классе.
// Класс декларацииC++ присваивает значения статическому массиву в классе
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Items
{
private:
string description;
public:
Items()
{
description = ""; }
Items(string desc)
{
description = desc;}
string getDescription() { return description; }
};
class InventoryItems {
public:
static Items inventory[5];
};
// main function
int main()
{
const int NUM = 3;
InventoryItems inv;
inv.inventory[0] = "Books";
for (int i = 0; i < NUM; i++)
{
cout << inv.inventory[i].getDescription() << endl;
}
return 0;
}
Я получаю ниже ошибки:
invMain.cpp:31: error: no match for operator= in InventoryItems::inventory[0] = "Books" invMain.cpp:7: note: candidates are: Items& Items::operator=(const Items&)
спасибо. Оно работает. Отлично. – hamid