- I am new to C++. Compiler is complaining about below line: inv.inventory[0] = "Books". Please help me how can I assign values to a static array in a Class.
// Class declaration
#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;
}
I am getting below error:
invMain.cpp:31: error: no match for operator= in InventoryItems::inventory[0] = "Books" invMain.cpp:7: note: candidates are: Items& Items::operator=(const Items&)