I have a class with its own get and set functions in it. I'm trying to get the user to input a value, then pass that value into a set function. But its giving me an error when I try to call that set function. Heres the code i'm trying to do:
1 2 3 4 5
out << "How much are you putting in?" << endl;
cout << "$";
cin >> getdollars;
cout << endl;
setdollars(getdollars);
I also tried
1 2 3 4 5
out << "How much are you putting in?" << endl;
cout << "$";
cin >> getdollars;
cout << endl;
retirement::setdollars(getdollars);
But they both give me an error
Am I calling the function correctly? setdollars is public, and I copied and pasted it from a few lines above.
the function I'm working in, is outside the class, but i'm not sure how that makes much difference.
If anyone knows what i'm doing wrong, i would apreciate any help.
Depends. If it is member function then no. If it is freestanding function then I do not see where there is mention of object value would be assigned to
fair enough, the function i'm working in is its own void function. and has no ties to the class i'm referencing. So i'm working in an independent void function, getting the user input data to a variable, then trying to pass that data to a public function in a class.
and the error i'm getting is: 'a nonstatic member must be relative to a specific object' when I hover over it. in the error log it says: error C2352: 'retirement::setdollars' : illegal call of non-static member function.
could the problem be that i'm working in a void function?
do you want to see the whole function? its more of the same with local variables for the user to store data before passing it into the assignment functions from the class. But I'll be more then happy to show you what i'm working with.
No, you have to create object. You have a class. It is leke a car blueprint. Can you drive blueprint? No, you need actual object. You don't do cout << int, you will do int x = 5; cout << x; So you should do the same for your class.
ok, if I'm understanding you, I need a class variable. do I have that right?
Something like 'retirement i;'
The goal of this program is to take all the user inputs and then mathematically figure out how much money they'll have after the amount of years they enter.
just as an example, they input something like
10
2
.05
30
Then plug all that information into a formula and spit out the answer. I was given a formula to work with, but I don't think I can represent it here very well.
Now another question, how can I pass in values from the class to math function. Please keep in mind I'm not using the main function yet. I'm trying to get away from using the main for anything but function calls. I did wind up using the retirement i variable. Why? to keep it simple, that's why.
Can I pass in i by reference? I'm a little hesitant to ask that, because i've only ever passed in a variable by reference once a few years back. and its been around a year since I even used a function to return any value outside of classes.