c++ - How can you access private string variables using member functions? -


I want to output the prices of private class members bank code and AgentName . How can I do this from the main () function, or in general, outside the BOURNE class?

My initial code endeavors are below:

  #include & lt; Iostream & gt; #include & lt; String & gt; using namespace std; Square Burn {String Bankcode = {"Secret Code is 00071712014"}; / * Private * / string agent name = {"Jason Bourne"} by default; / * Private * / Public by default: Zero tryToGetSecretCodeandName (string theName, string theCode); // Private Zero TrytoGetAgentName (name of the string) is trying to get; // try to get the name}; // * * *************************** :: tryToGetSecretCodeandName (string theName, string theCode) // member defined function {Bankcode = theCode; // For the code here, the equivalent name is AgentName = theName; // Here's the samething court & lt; & Lt; TheCode & lt; & Lt; "\ N" & lt; & Lt; TheName; // print the values} // ************************************************************************************** ******************************************************************************************************************** Object.ToToGetSecretCodeandName (); Return 0; }    

third answer

There are two 'Gator' style functions in your code, but no one takes the argument. This is the reason why both of your tasks require logic to be passed.

Your main task is to get ... codeandName () which is calling any arguments . As such, you get a compiler error, possibly complaining about valid signatures, or passing arguments.

Edit Answer If you want to get only values, so typical (as far as I know) implementation is something

  std: : String bore :: getCode () {back bankcode; } Std :: string Born :: getName () {Return agent agent; } Int main () {Born Mary Edgent; The court's & lt; & Lt; "The name of the agent is:" & lt; & Lt; MyAgent.getName () & lt; & Lt; Endl; The court's & lt; & Lt; "The agent's code is:" & lt; & Lt; MyAgent.getCode () & lt; & Lt; Endl; }   

left the original answer because I think it is more useful

I doubt what you are asking if you can have something like

  void Boren :: tryToGetSecretCodeandName (string theName, string theCode) {if (Bankkod == theCode) {cout & lt do; & Lt; "You have guessed the correct code:" & lt; & Lt; Bank code & lt; & Lt; Endl; } If (Agent name == theName) {cout & lt; & Lt; "You have correctly estimated the name of the agent:" & lt; & Lt; Agent name & lt; & Lt; Endl; }}   

This will allow you to guess the name over and over again, and get the output when you are right.

If you want to disable this kind of guesswork, then you might consider creating a new class (probably based on std :: string - but See due to being careful) and implement a operator == function that is always false . was returned

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -