use a '&' to create a pointer to member


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
//list of variables
		char fileTag_;
		char typeIndicator;
		char perishableSku[max_sku_length+1];
		char *arrayHolder;
		char productUnit[max_unit_length+1];
		int currentQuantity;
		int demandQuantity;
		double originalPrice;
		bool taxAvailability;
//these two are setters
	void NonPerishable::sku(const char *t_sku) { strncpy(perishableSku, t_sku, max_sku_length); }

	void NonPerishable::price(double price) { originalPrice = price; }


//these two are getters
const char* NonPerishable::sku() const {
		return perishableSku;
	}

int NonPerishable::price() const {
		return originalPrice;
	}

  	NonPerishable::NonPerishable(const NonPerishable& oitem) {
		sku(oitem.sku);
		name(oitem.arrayHolder);
		price(oitem.price);
		taxed(oitem.taxAvailability);
		quantity(oitem.currentQuantity);
		qtyNeeded(oitem.demandQuantity);
	}
	NonPerishable& NonPerishable::operator=(const NonPerishable& oldItem) {
		if (this != &oldItem && !oldItem.isEmpty()) {
			sku(oldItem.sku);
			name(oldItem.arrayHolder);
			price(oldItem.originalPrice);
			taxed(oldItem.taxAvailability);
			quantity(oldItem.currentQuantity);
			qtyNeeded(oldItem.demandQuantity);
		}

	}


It gives me an error saying use & to create a pointer to member at line 27, 29, 36
Anyone knows the solution?
Last edited on
What are you attempting to do on lines 27, 29, and 36?

If you're trying to call NonPerishable::sku or NonPerishable::price, your syntax doesn't make much sense. I'm not just being vague on purpose, I'm not sure what to say. You're trying to call a function sku, but the input to the function is the name of the same function.

Perhaps start by saying what you think lines 27, 29, and 36 are supposed to be doing?

Edit: perhaps you meant to do
sku(oitem.perishableSku); ?
and
price(oitem.originalPrice); ?

The input to your sku function should be a const char* (AKA a C string, or can be a raw char array), and the input to your price function should be a double.
Last edited on
ad () to the end of the function call. E.g. line 27:

sku(oitem.sku())

otherwise you try to store the address of the function.
The problem with that is sku is a "setter" function in his code, coder777. It returns void.
@Ganado

No, there are both. See line 12 and 18.
Registered users can post here. Sign in or register to post.