I am a beginner and I came across a problem that may be a step too big for my legs. And if it is I would be very grateful if I was told so.
I defined a a class like this:
"price::price(string id, double u_price, double p_price, double quant):ident_(id), u_price_(u_price), p_price_(p_price), quant_(quant) {};
This class creates me objects with a letter and three numbers. My idea now was create a function to which I can give a string and it will return the unitary_price() of the corresponding price object.
Based on code I saw, but perhaps I did not understood it entirely, this is the function I added to the class I created:
" double price::relate_identifier_u_price(string fake){
price * product;
fake = product->identifier();
double charge = product->unitary_price();
return charge;
} "
When I try to use this function on the file that contains the int main() function:
First answer these questions for yourself:
Is dice a function or a variable?
Where is it defined?
Ask again if you still cant understand.
If you are an absolute beginner in programming, for at least once, read tutorial such as this before pasting random code without understanding http://www.cplusplus.com/doc/tutorial/
In this piece, I have a pointer to "producta" and, throw it, I can obtain all the information contained in the object. Here, I give the object, and I extract all about it.
Would it be possible to recover all the information of the object by just giving one of its properties? Would it be possible to write a function where I could give the string "a" and obtain the value of s1 (50)?
I tried to write such a function, but is obviously wrong. Could some tell me how this is done?
Thank you.
It doesn't work the way you're thinking.
However, you can do it by having each price object register itself with a static map that maps the identifiers to the actual objects.