How to mock static method call by constructor?

C++, how to set information when calling the method of a class?

  • An example of what I'm trying to do is: If we created a method of the class Person and Katie called that method, how would we set Katie’s age to 2 within that method? How would we set Katie’s hair color to red within that method? How would we write the call to the method? How would you do this with c++ code? I'm trying to figure out not only what the code would be, but also what's going on, like if a constructor function, friend function, etc. is being used.

  • Answer:

    consider the class class person { private : int Age ; char Haircolor[10]; public void setAge(int p_age ) { Age=p_age ; } public void setHairColor(char[] p_haircolor) { Haircolr = p_haircolor; } } void main() { person Katie ; Katie.setAge(20); Katie.setHairColor("Red"); }

Will at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

So you have a class Person, and an object Katie of class Person. You would create a method setAge(int value); and in that method you set the private data member 'age' of object Katie to age = value. That's one example.

therandomer

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.