Error around pointers, I think.

Sooo heres the stuff, its on line 53 or the part that ive commented off. The error is 'Item::clone':non-newboi standard syntax; use '&' to create a pointer to member.
There's another error around the same line of code, and it reads'=' cannot convert from 'Item*(_thiscallItem::*)(void)const' to 'Item*'.
I'm pretty sure the two are related lmao

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "Inventory.h"



Inventory::Inventory()
{
	cap = 10;
	numOfItems = 0;
	itemsArr = new Item*[cap];
}


Inventory::~Inventory()
{
	for (size_t i = 0; i < this->numOfItems; i++)
	{
		delete this->itemsArr[i];
	}
	delete itemsArr;
}

void Inventory::expand()
{
	this->cap *= 2;
	Item **tempArr = new Item*[this->cap];

	for (size_t i = 0; i < this->numOfItems; i++)
	{
		tempArr[i] = this->itemsArr[i];
	}

	delete[] this->itemsArr;

	this->itemsArr = tempArr;

	this->initialize(this->numOfItems);
}

void Inventory::initialize(const int from)
{
	for (size_t i = from; i < this->cap; i++)
	{
		itemsArr[i] = nullptr;
	}
}

void Inventory::addItem(const Item &item)
{
	if (this->numOfItems >= this->cap)
	{
		expand();
	}
//This is the problem child->	this->itemsArr[this->numOfItems++] = item.clone;
}

void Inventory::removeItem(int index)
{

}


here's the header file the cpp file is including as well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef ITEM_H
#define ITEM_H

#include <string>
#include <iostream>
#include <iomanip>


class Item
{
public:
	Item(std::string name = "NONE", int level = 0, int buyValue = 0, int sellValue = 0, int rarity = 0);
	~Item();

	inline std::string debugPrint()const { return this->name; }
	virtual Item* clone()const = 0;

	//accessors
	inline const std::string& getName() const { return this->name; }
	inline const int& getLevel() const { return this->level; }
	inline const int& getBuyValue() const { return this->buyValue; }
	inline const int& getSellValue() const { return this->sellValue; }
	inline const int& getRarity() const { return this->rarity; }

	//modifiers
private:
	std::string name;
	int level;
	int buyValue;
	int sellValue;
	int rarity;
};

#endif 
Did you mean item.clone() (the parentheses are mandatory when calling functions)?
wow I actually didn't see that
Topic archived. No new replies allowed.