Hello,
I programm an account programm which stores name and password for a new account in accordance to different rules.
1. Question on constant variable
I first get the user input (see code below) and then transfer the data from a public to a private variable within my class. For my private variable name_, I would like it to get constant after copying the n_ value. So from this point in my programm, it shall be constant, but of course I require the first input. If I use "const" my programm does not allow any change to name_. Is there any possibility? I would expect this kind of programming to be a general approach, so that variables are constant from a certain point on.
It might be that pointer are a solution, but I do not understand them well until now.
2. Return
I would like to have the getName_() method in my class only for the function to get the name. To check if it is correct, I want to create a checkName() method. Until now I have the complete function in one method which works.
I now try to pass the name_ variable from my getName() to the checkName() which are both inside the class on the same level.
I tried it to declare the functions as friend and to "return name_" (which is a CString). Both do not work. In general I have the problem that 2 functions within the same class do not know each other.
Is there any general approach?
1 2 3 4 5 6 7 8 9 10
|
...
Account::getName_()
{
Acc_Popup: cout << "Please type in your new account; no space is allowed" << endl;
getline(std::cin,n_); // n_ is public variable
name_ = n_; //name is private variable
/*... Thereafter I perform certain checks. If true I write the name_ to a file,
if false I perform an error with try, throw, catch. */
|