Action with indicators



  • public:
    Integer(int n=0): num(n){}
    void get_Sum(const Number &n)
    {
        num += ((Integer*)&n)->num;
    }
    

    Please explain how the function works. get_Sum♪ What's that? (Integer*)&n and ->num



  • Function get_Sum(const Number&) Accepts as an argument the variable type Number reference (from use &)

    Internal functions:

    1. &n = index to memory area where variable value is stored n
    2. (Integer*) &n - type indicator received Number* Bring it to the type indicator Integer*
    3. ((Integer*) &n)->num - with a type-indicator Integer*We're talking to the field. num Class Integer variable n



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2