Class: Non-Standard Syntax

I am a newbie when it comes to classes in C++, and I have to create a program that uses a class involved with retail items at a store. I have to create three items under this class with class members containing the item description, units, and price.

Here is my header file RetailItem.h:
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
#pragma once
#include <string>
#include <iostream>
using namespace std;

class RetailItem
{
private:
	string description;
	int unitsOnHand;
	double price;
public:
	//Constructor Functions
	RetailItem(); //Default Constructor
	RetailItem(string Name, int Units, double Price); //Regular Constructor
	//Destructor Function
	~RetailItem();
	//Accessor Functions
	double getPrice() const;
	int getUnits() const;
	string getName() const;
	//Mutator Functions
	void setItem(string Name, int Units, double Price);
	void setName(string Name);
	void setUnits(int Units);
	void setPrice(double Price);
};


Here is my .cpp file for the Class:
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
60
61
62
63
64
65
#include "stdafx.h"
#include "RetailItem.h"
#include <string>
#include <iostream>

using namespace std;

//Default Constructor
RetailItem::RetailItem()
{
	description = "Sweatpants";
	unitsOnHand = 15;
	price = 20.00;
}

//Regular Constructor
RetailItem::RetailItem(string Name, int Units, double Price)
{
	description = Name;
	unitsOnHand = Units;
	price = Price;
}

//Accessor Methods
double RetailItem::getPrice() const
{
	return price;
}

int RetailItem::getUnits() const
{
	return unitsOnHand;
}

string RetailItem::getName() const
{
	return description;
}

//Mutator Methods
void RetailItem::setItem(string Name, int Units, double Price)
{
	description = Name;
	unitsOnHand = Units;
	price = Price;
}

void RetailItem::setName(string Name)
{
	description = Name;
}

void RetailItem::setUnits(int Units)
{
	unitsOnHand = Units;
}

void RetailItem::setPrice(double Price)
{
	price = Price;
}
//Destructor
RetailItem::~RetailItem()
{
}


...and here is my main program
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "stdafx.h"
#include <iostream>
#include <string>
#include "RetailItem.h"

using namespace std;

int main()
{
	RetailItem item1, item2, item3;
	string name;
	int units;
	double price;

	cout << "Welcome to the Retail store!" << endl;

	//Item 1
	//Price
	cout << "Please enter the price for item 1: ";
	cin >> price;
	while (price <= 0)
	{ 
		cout << "Price must be greater than 0." << endl;
		cout << "Please enter the price for item 1: ";
		cin >> price;
	}
	item1.setPrice(price); //Mutator Method

	//Inventory
	cout << "Please enter the units on hand for item 1: ";
	cin >> units;
	while (units <= 0)
	{
		cout << "Inventory must be greater than 0." << endl;
		cout << "Please enter the units on hand for item 1: ";
		cin >> units;
	}
	item1.setUnits(units); //Mutator Method

	//Description
	cout << "Please enter the description for item 1: ";
	cin >> name;
	item1.setName(name); //Mutator Method

	//Item 2
	//Price
	cout << "Please enter the price for item 2: ";
	cin >> price;
	while (price <= 0)
	{
		cout << "Price must be greater than 0." << endl;
		cout << "Please enter the price for item 2: ";
		cin >> price;
	}
	item2.setPrice(price); //Mutator Method

	//Inventory
	cout << "Please enter the units on hand for item 2: ";
	cin >> units;
	while (units <= 0)
	{
		cout << "Inventory must be greater than 0." << endl;
		cout << "Please enter the units on hand for item 2: ";
		cin >> units;
	}
	item2.setUnits(units); //Mutator Method

	//Description
	cout << "Please enter the description for item 2: ";
	cin >> name;
	item2.setName(name); //Mutator Method

	//Item 3 has Default Values.

	//Display Items
	cout << endl << endl;
	cout << "Display all items" << endl;
	//Item 1
	cout << "Description: " << item1.getName << endl;
	cout << "Units on hand: " << item1.getUnits << endl;
	cout << "Price: $" << item1.getPrice << endl << endl;
	//Item 2
	cout << "Description: " << item2.getName << endl;
	cout << "Units on hand: " << item2.getUnits << endl;
	cout << "Price: $" << item2.getPrice << endl << endl;
	//Item 3
	cout << "Description: " << item3.getName << endl;
	cout << "Units on hand: " << item3.getUnits << endl;
	cout << "Price: $" << item3.getPrice << endl;

    return 0;
}


I keep getting the error 'RetailItem::getName': non-standard syntax; use & to create a pointer to member from lines 82 to 92 for all of my getName, getUnits, and getPrice methods. I am not sure what to do. Thank you for your time.
Last edited on
They are functions. You are missing the parentheses to indicate a function call.
 
cout << "Description: " << item1.getName() << endl;

Wow, I cannot believe I forgot those! I feel so dumb haha. Thank you so much!!!
Topic archived. No new replies allowed.