| | |
Getting a constant conversion error
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 226
Reputation:
Solved Threads: 1
I'm having a little problem with a conversion error during compile. Here is the code:
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?
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; class costOfItem { public: costOfItem(float i_cost); void printMe(); private: const float price; }; // Free functions void displayPrice(costOfItem z) { z.printMe(); } void displayRefPrice(costOfItem &z) { z.printMe(); } void displayConstRef(const costOfItem &z) { z.printMe(); }
•
•
Join Date: Jun 2007
Posts: 275
Reputation:
Solved Threads: 45
Both the member function declaration and definition will require the const modifier. This tells the compiler that the function is an 'inspector' function and will not modify anything in the object (which is required when using a const object).
About your 'this' question, 'this' is a pointer to the instance of the object.
About your 'this' question, 'this' is a pointer to the instance of the object.
![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Overloaded + operator not working correctly. (C++)
- c++ compilation error (C++)
- C++ const help (C++)
- FILE + conversion from dec to hex = I need help (C)
- help with conversion calculator (C)
- file input don't know where to start (C++)
- help needed with errors (C++)
- plzzz help! i did the work need (C)
Other Threads in the C++ Forum
- Previous Thread: C++ Bubble sort not working with array of records, does work with simple array.
- Next Thread: test
Views: 431 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project python random read recursion recursive reference return sort stream string strings struct studio system template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






