Getting C2084 error Please Help!!!

Heres the Item.h file code:

#pragma once
#include <string>
using namespace std;

class Item
{
private:
double price;
int weight;
string description;
int quantity;

public:
Item(void) {
}
Item(double price, int weight, string decription) {
}
void setQuantity(int quant);
double getOrderPrice();
int getOrderWeight();
void show();
};

AND HERES THE MAIN.CPP file code:

#include <iostream>
#include <string>
#include "Item.h"
using namespace std;

int main() {
double dTotalPrice = 0.0;
int iTotalWeight = 0;
Item itmMouse(24.99, 14, "Wireless Mouse");
Item itmKeyboard(22.49, 27, "USB Keyboard");
Item itmHDMI(24.99, 12, "HDMI Cable");
Item itmGlasses(7.99, 7, "Reading Glasses");
itmGlasses.setQuantity(2);
// Show the details of the order using printDetails()
cout << "Here are your shopping cart contents.\n";
itmMouse.show();
itmKeyboard.show();
itmHDMI.show();
itmGlasses.show();
// Compute the total price and total weight in this section
dTotalPrice += itmMouse.getOrderPrice();
dTotalPrice += itmKeyboard.getOrderPrice();
dTotalPrice += itmHDMI.getOrderPrice();
dTotalPrice += itmGlasses.getOrderPrice();
iTotalWeight += itmMouse.getOrderWeight();
iTotalWeight += itmKeyboard.getOrderWeight();
iTotalWeight += itmHDMI.getOrderWeight();
iTotalWeight += itmGlasses.getOrderWeight();
// Here we show the order details
cout << "The price of your order is $" << dTotalPrice << endl;
cout << "The shipping weight is " << iTotalWeight << " ounces\n";
cout << "That is " << iTotalWeight / 16.0 << " pounds\n";

return 0;
}

AND IF YOU NEED HERES THE Item.cpp FILE CODE:

#include <iostream>
#include <string>
#include "Item.h"
using namespace std;

Item::Item(void) {
price = 0;
weight = 0;
quantity = 0;
}
Item::Item(double price, int weight, string decription) {
quantity = 1;
}
void Item::setQuantity(int quant) {
quantity = quant;
}
double Item::getOrderPrice() {
return price;
}
int Item::getOrderWeight() {
return weight;
}


PLEASE HELP ME IM TRYING TO LEARN, but the situation is that the main.cpp file code is all correct and given by my professor, i just have to make the classes and objects code work to allow the main.cpp file to run.
In the future, Please use code tags when you post. It makes the code easier for people to read. Code tags is on a little menu to the right side of your screen when you post. It's the button that looks like this <>. Just click on it and paste your code between the tags.

Give this a try.
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
#include <string>
using namespace std;

class Item
{
private:
	double price;
	int weight;
	string description;
	int quantity;

public:
	Item();
	Item(double pri, int wei, string decrip);
	void setQuantity(int quant);
	double getOrderPrice();
	int getOrderWeight();
	void show();
};


Item::Item() 
{
	price = 0;
	weight = 0;
	quantity = 0;
}
Item::Item(double pri, int wei, string decrip) 
{
	price = pri;
	weight = wei;
	description = decrip;
	quantity = 1;
}
void Item::setQuantity(int quant) 
{
	quantity = quant;
}
double Item::getOrderPrice() 
{
	return price * quantity;
}
int Item::getOrderWeight() 
{
	return weight * quantity;
}

void Item::show()
{
	cout << "Item: " << description << " details" << endl;
	cout << "Price = " << price << endl;
	cout << "Quantity = " << quantity << endl;
	cout << "Weight = "<< weight << endl;
}



The error you were getting was because of these statements
1
2
3
4
	Item(void) {
	}
	Item(double price, int weight, string decription) {
	}


You don't need the braces because the constructor definition is in another file so it should look like this.
1
2
	Item();
	Item(double pri, int wei, string decrip);
Last edited on
Topic archived. No new replies allowed.