954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help solving errors: C2533, C2511, C2144.

I've been trying to fix these errors for a while now and I'm having difficulty. Can anyone help? I've attached my header file, .cpp file and main.

The C2533 and C2511 are both in my .cpp file.
c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\invoice.cpp(15) : error C2533: 'Invoice::{ctor}' : constructors not allowed a return type
c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\invoice.cpp(113) : error C2511: 'void Invoice::print(Invoice)' : overloaded member function not found in 'Invoice'
c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\invoice.h(11) : see declaration of 'Invoice'

The C 2144 error is in my main.

c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\main.cpp(15) : error C2144: syntax error : 'int' should be preceded by ';'

Attachments Invoice.cpp (3.62KB) Invoice.h (1.34KB) main.cpp (3.59KB)
acperson
Newbie Poster
20 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

The problem is at the last line of invoice.h -- a semicolon is required at the end of a class declaration.

Ancient Dragon
Retired & Loving It
Team Colleague
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

Thanks so much!

That solves two errors, but the C2511 is still there.

acperson
Newbie Poster
20 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

The error is as follows:

c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\invoice.cpp(113) : error C2511: 'void Invoice::print(Invoice)' : overloaded member function not found in 'Invoice'
c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\invoice.h(11) : see declaration of 'Invoice'

My program code is attached. Please help. This assignment is due at midnight and I can't get the bloody thing to even compile so that I can start debugging.

It involves this line:

void Invoice::print(Invoice *bill)
{			//print values in current bill


Which comes from:

class Invoice
{	
...

void print(Invoice *) const;


Thanks!

Attachments Invoice.cpp (3.62KB) Invoice.h (1.38KB) main.cpp (3.63KB)
acperson
Newbie Poster
20 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Several problems
1) add the const keyword

2) need to add () to function method calls

void Invoice::print(Invoice bill) const 
{											//print values in current bill
	cout<<"Invoice Number: "<<bill.getInvoiceNum()<<endl<<endl;
	cout<<"Part Number: "<<bill.getPartNum()<<endl;
	cout<<"Part Description: "<<bill.getPartDesc()<<endl;
	cout<<"Quantity Shipped: "<<bill.getQuantityShip()<<endl;
	cout<<"Unit Price ($/item): "<<bill.getUnitPrice()<<endl;
	cout<<"Sales Tax Rate: "<<bill.getSalesTaxRate()<<endl;
	cout<<"Sales Tax Amount: "<<bill.calcSalesTaxAm()<<endl;
	cout<<"Shipping Cost: "<<bill.getShipCost()<<endl;
	cout<<"Total Cost: "<<bill.calcTotCost()<<endl;
}
Ancient Dragon
Retired & Loving It
Team Colleague
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

In Invoice.h you declare this function:

void print(Invoice) const;

However, I don't think you can use Invoice as a parameter to a class member funtion in the Invoice class delaration because the class hasn't been fully declared yet. You can have a pointer to class type in the class declaration, though. For your purposes I don't think you want either. I'd declare print() to have a void parameter list. It would be used to print() the Invoice invoking it. That is:
Invoice i;
i.print();
will print the Invoice object called i.

But then again, I've been wrong before.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

Several problems 1) add the const keyword

2) need to add () to function method calls

void Invoice::print(Invoice bill) const 
{											//print values in current bill
	cout<<"Invoice Number: "<<bill.getInvoiceNum()<<endl<<endl;
	cout<<"Part Number: "<<bill.getPartNum()<<endl;
	cout<<"Part Description: "<<bill.getPartDesc()<<endl;
	cout<<"Quantity Shipped: "<<bill.getQuantityShip()<<endl;
	cout<<"Unit Price ($/item): "<<bill.getUnitPrice()<<endl;
	cout<<"Sales Tax Rate: "<<bill.getSalesTaxRate()<<endl;
	cout<<"Sales Tax Amount: "<<bill.calcSalesTaxAm()<<endl;
	cout<<"Shipping Cost: "<<bill.getShipCost()<<endl;
	cout<<"Total Cost: "<<bill.calcTotCost()<<endl;
}

This just gives me more errors.

c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\invoice.cpp(121) : error C2039: 'getShippingCost' : is not a member of 'Invoice'
c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\invoice.h(14) : see declaration of 'Invoice'
Generating Code...
Compiling...
main.cpp
c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\main.cpp(65) : error C2664: 'Invoice::print' : cannot convert parameter 1 from 'Invoice *' to 'Invoice'
No constructor could take the source type, or constructor overload resolution was ambiguous

acperson
Newbie Poster
20 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Ok, now I'm down to one error in main.

c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\main.cpp(65) : error C2664: 'Invoice::print' : cannot convert parameter 1 from 'Invoice *' to 'Invoice'
No constructor could take the source type, or constructor overload resolution was ambiguous

for the line:

bill[place].print(bill);
acperson
Newbie Poster
20 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Ok, now I'm down to one error in main.

c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\main.cpp(65) : error C2664: 'Invoice::print' : cannot convert parameter 1 from 'Invoice *' to 'Invoice'
No constructor could take the source type, or constructor overload resolution was ambiguous

for the line:

bill[place].print(bill);
acperson
Newbie Poster
20 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

look at the parameter in the .h file -- it is a pointer. Now look at the parameter in the line you quoted -- that is NOT a pointer. They have to be consistent, one of the two has to be changed.

Ancient Dragon
Retired & Loving It
Team Colleague
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

>>'getShippingCost' is not a member of 'Invoice'

Yes -- you didn't see the code I posted earlier?

Ancient Dragon
Retired & Loving It
Team Colleague
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

I have tried changing them. it backfires every time. is there any way I could supply an explicit conversion?

acperson
Newbie Poster
20 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Don't create two threads about the same problem. I merged your two threads and don't intend to do it again!

Ancient Dragon
Retired & Loving It
Team Colleague
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

oh. sorry. I'm just really trying to get this done in time. I had 5 due tonight (with only 1 1/2 weeks to do them) and I only have 3 completely finished. The last one isn't getting done because I don't have time to type the code up and then compile it and debug. So I need this one to be as good as it can...

sorry about that...

acperson
Newbie Poster
20 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 
>> Yes -- you didn't see the code I posted earlier?

Is this in response to supplying an explicit conversion? Because if so, I'm still doing something else wrong because i have the same thing in the code box you provided.

acperson
Newbie Poster
20 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

The print() method doesn't need a parameter at all.

This time read all the code and correct the spelling as I did.

Invoice.cpp

void Invoice::print() 
{											//print values in current bill
	cout<<"Invoice Number: "<<getInvoiceNum()<<endl<<endl;
	cout<<"Part Number: "<<getPartNum()<<endl;
	cout<<"Part Description: "<<getPartDesc()<<endl;
	cout<<"Quantity Shipped: "<<getQuantityShip()<<endl;
	cout<<"Unit Price ($/item): "<<getUnitPrice()<<endl;
	cout<<"Sales Tax Rate: "<<getSalesTaxRate()<<endl;
	cout<<"Sales Tax Amount: "<<calcSalesTaxAm()<<endl;
	cout<<"Shipping Cost: "<<getShipCost()<<endl;
	cout<<"Total Cost: "<<calcTotCost()<<endl;
}


invoice.h

void print();


main.cpp

if (bill[place].getInvoiceNum() == inum)
Ancient Dragon
Retired & Loving It
Team Colleague
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

Thanks for replying and all the help you've given me thus far!

Well, when I do that I get 9 occurrences of the same error - one per line.

c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\invoice.cpp(114) : error C2662: 'Invoice::getInvoiceNum' : cannot convert 'this' pointer from 'const Invoice' to 'Invoice &'
Conversion loses qualifiers

acperson
Newbie Poster
20 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

in main you call print() on an Invoice object just like you call getInvoiceNum() or one of the other plublic methods.

bill[place].print();

assuming you've changed the print() method to have a void parameter list.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

Ok, fixed that one. That was my fault for not checking my code exactly. I left const in the .h file.

But...now I'm back to that blasted C2511 error.

c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\invoice.cpp(113) : error C2511: 'void Invoice::print(void) const' : overloaded member function not found in 'Invoice'
c:\documents and settings\tina\my documents\visual studio 2008\projects\csci112lab4\csci112lab4\invoice.h(14) : see declaration of 'Invoice'

acperson
Newbie Poster
20 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Did you update the declaration of print() in the .h file and the definition of print() in the .cpp file to correspond with the new signature of print()?

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You