Constructor with strings - Errors

Hi all,
I am trying to create a tool which contains part#, Part Description, Price and Qty. From what I defined I want it to calculate the total price (price*qty) and have it output those 4 data members and the invoice. But I am getting errors on my code. I feel I am not setting up my constructor properly for strings...

Here is my error

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
invoice.cpp: In constructor ‘invoice::invoice()’:
invoice.cpp:18:12: error: invalid use of member function (did you forget the ‘()’ ?)
  m_partNum = "0";
            ^
invoice.cpp:19:13: error: invalid use of member function (did you forget the ‘()’ ?)
  m_partDesc = "0";
             ^
invoice.cpp:20:8: error: invalid use of member function (did you forget the ‘()’ ?)
  m_qty = 0;
        ^
invoice.cpp:21:10: error: invalid use of member function (did you forget the ‘()’ ?)
  m_price = 0;
          ^
invoice.cpp: In constructor ‘invoice::invoice(std::string, std::string, int, double)’:
invoice.cpp:27:13: error: invalid use of member function (did you forget the ‘()’ ?)
   m_partNum = partNum;
             ^
invoice.cpp:28:14: error: invalid use of member function (did you forget the ‘()’ ?)
   m_partDesc = partDesc;
              ^
invoice.cpp:29:9: error: invalid use of member function (did you forget the ‘()’ ?)
   m_qty = reqQty;
         ^
invoice.cpp:30:11: error: invalid use of member function (did you forget the ‘()’ ?)
   m_price = reqQty;
           ^
invoice.cpp: At global scope:
invoice.cpp:36:14: error: ‘account’ has not been declared
 const double account::get_invoice() {
              ^
invoice.cpp: In function ‘const double get_invoice()’:
invoice.cpp:37:9: error: ‘m_qty’ was not declared in this scope
  return m_qty * m_price;
         ^
invoice.cpp:37:17: error: ‘m_price’ was not declared in this scope
  return m_qty * m_price;
                 ^
invoice.cpp: At global scope:
invoice.cpp:41:6: error: ‘account’ has not been declared
 void account::deposit(double amount){
      ^
invoice.cpp: In function ‘void deposit(double)’:
invoice.cpp:47:3: error: ‘m_balance’ was not declared in this scope
   m_balance = m_balance + amount;
   ^
invoice.cpp: At global scope:
invoice.cpp:53:39: error: no ‘const string invoice::asstring() const’ member function declared in class ‘invoice’
 const std::string invoice::asstring() const{  

^

My header
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
#ifndef invoice_h_
#define invoice_h_

#include <iostream>
#include <string>


class invoice
{
public:
	invoice(std::string partNum,
			std::string partDesc,
			int reqQty, 
			double price);
	invoice();
	~invoice();
//----------------------------------------------------
   	//Qty
   	void qty(int req);
//----------------------------------------------------
   	// Get Partnum
   	const std::string get_partnum() const;
    //----------------------------------------------------
   	// Get Partnum
   	const std::string get_partdesc() const;
   	//----------------------------------------------------
   	// Get Partnum
   	const int get_qty() const;
   	//----------------------------------------------------
   	// Get Partnum
   	const double get_price() const;
//----------------------------------------------------
   	// Set Partnum
   	void set_partnum(std::string sPartnum);
   	//----------------------------------------------------
   	// Set Partdesc
   	void set_partdesc(std::string sPartdesc);
   	//----------------------------------------------------
   	// Set Qty
   	void set_qty( int sqty);
   	//----------------------------------------------------
   	// Set price
   	void set_price( double sprice);
//----------------------------------------------------
   	//Invoice Amt
   	const double get_invoice() const;
//----------------------------------------------------
   	//display string
   	const std::string asstring() const;  	
	
private:
	//----------------------------------------------------
	//Part number
	std::string m_partNum();
	//----------------------------------------------------
	//Part Description
	std::string m_partDesc();
	//----------------------------------------------------
	//Price
	double m_price();
	//----------------------------------------------------
	//Qty
	int m_qty();


};

#endif 


my prog
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
#include <iostream>
#include <sstream>
#include <string>
#include <stdlib.h>
#include "invoice.h"
using namespace std;


//----------------------------------------------------
//Invoice Default
invoice::invoice(){
	m_partNum = "0";
	m_partDesc = "0";
	m_qty = 0;
	m_price = 0;
}
invoice::invoice(std::string partNum, 
				std::string partDesc,
				int reqQty, 
				double price){
		m_partNum = partNum;
		m_partDesc = partDesc;
		m_qty = reqQty;
		m_price = reqQty;
}
invoice::~invoice(){	
}
//----------------------------------------------------
//get balance
const double account::get_invoice() {
	return m_qty * m_price;
}
//----------------------------------------------------
//deposit
void account::deposit(double amount){
	if(amount <= 0){
		std::cout <<"The deposit is less than or equal to 0. "
		<< amount << endl;
	}
	else{
		m_balance = m_balance + amount;
	}
}

//----------------------------------------------------
//display
const std::string invoice::asstring() const{
	ostringstream oss;

	oss << "Part# : " << m_partNum <<
		   "Part Desc : " << m_partDesc <<
		   "Qty : " << m_qty <<
		   "Price : " << m_price;
	return oss.str();
}
Last edited on
std::string m_partNum();

This is the declaration of a function named m_partNum which takes no arguments and returns a string.

Try: std::string m_partNum;
Ok now I am getting alot of
1
2
3
4
invoice.cpp: In constructor ‘invoice::invoice()’:
invoice.cpp:20:8: error: invalid use of member function (did you forget the ‘()’ ?)
  m_qty = 0;
        ^

Same with line 21, 29, 30 for the error above
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

invoice.cpp: At global scope:
invoice.cpp:36:14: error: ‘account’ has not been declared
 const double account::get_invoice() {
              ^
invoice.cpp: In function ‘const double get_invoice()’:
invoice.cpp:37:9: error: ‘m_qty’ was not declared in this scope
  return m_qty * m_price;
         ^
invoice.cpp:37:17: error: ‘m_price’ was not declared in this scope
  return m_qty * m_price;
                 ^
invoice.cpp: At global scope:
invoice.cpp:41:6: error: ‘account’ has not been declared
 void account::deposit(double amount){
      ^
invoice.cpp: In function ‘void deposit(double)’:
invoice.cpp:47:3: error: ‘m_balance’ was not declared in this scope
   m_balance = m_balance + amount;
   ^ 

Then I get a bunch of these overloaded function errors as seen below
1
2
3
4
5
invoice.cpp: In member function ‘const string invoice::asstring() const’:
invoice.cpp:58:15: error: no match foroperator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘<unresolved overloaded function type>’)
      "Qty : " << m_qty <<
               ^
Last edited on
You have the same problem with m_qty as you did with m_partnum. You get the same error message, so I figured you'd catch on.

As for the places where you try to define a function for a type (account) which doesn't exist as far as I can tell... don't do that.
Makes sense. Should have caught onto that one. Guess I was working on it to late at night and was in a daze. Appreciate the help!!!
Topic archived. No new replies allowed.