View Single Post
Join Date: Dec 2007
Posts: 226
Reputation: henpecked1 is an unknown quantity at this point 
Solved Threads: 1
henpecked1 henpecked1 is offline Offline
Posting Whiz in Training

Getting a constant conversion error

 
0
  #1
May 9th, 2008
I'm having a little problem with a conversion error during compile. Here is the code:

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class costOfItem
  5. {
  6. public:
  7. costOfItem(float i_cost);
  8. void printMe();
  9.  
  10. private:
  11. const float price;
  12.  
  13. };
  14. // Free functions
  15. void displayPrice(costOfItem z) { z.printMe(); }
  16. void displayRefPrice(costOfItem &z) { z.printMe(); }
  17. void displayConstRef(const costOfItem &z) { z.printMe(); }
Now in the last line it gives me the error cannot convert 'this' pointer from const costOfItem to costOfItem conversion loses qualifiers. I'm assuming there is a problem with the current instance of the object (which I believe is what 'this' points to, please correct me if I'm wrong about that) and it seems to be trying to convert it to a non const. What seems to be the problem and how do I fix it?
Reply With Quote