Problem declaring class array? *new to classes*

Write your question here.

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
#pragma once
#include "stdafx.h"
#include<iostream>


using namespace std;

class Invoice
{
public:
	int getPartNum() const;
	string getPartDes() const;
	int getQuantity() const;
	double getPrice() const;
	Invoice();
	~Invoice();


private:
	int partNum;
	string partDes;
	int quantity;
	double price;
};


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
// Unit 14.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include "Invoice.h"

using namespace std;


int main()
{
	Invoice invoices[8] = {
		new Invoice(83, "Electric sander", 7, 57.98),
		new Invoice(24, "Power saw", 18, 99.99),
		new Invoice(7, "Sledge hammer", 11, 21.5),
		new Invoice(77, "Hammer", 76, 11.99),
		new Invoice(39, "Lawn mower", 3, 79.5),
		new Invoice(68, "Screwdriver", 106, 6.99),
		new Invoice(56, "Jig saw", 21, 11.00),
		new Invoice(3, "Wrench", 34, 7.5)
	};


    return 0;
}
closed account (E0p9LyTq)
You don't have a class constructor that takes any parameters, as you are trying to use. The sole constructor you have specified is the default constructor (Invoice()).

Declare and define an overloaded constructor that takes 4 parameters -- an int, a std::string, an int and a double.

8
9
10
11
12
13
14
class Invoice
{
public:
   Invoice();
   Invoice(int, std::string, int, double);
   // rest of your class
};
I actually realized I was missing the constructor before I came back to check on the thread, but thanks for the quick response!
Topic archived. No new replies allowed.