We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. C++
  3. Inheritance
  4. Accessing Inherited Functions
  5. Discussions

Accessing Inherited Functions

Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • andrewrf6h6
    6 months ago+ 1 comment

    Solve it:

    class D: public A, public B, public C
    {
    ...
    		 //Implement this function
    		 void update_val(int new_val)
    		 {
                while (new_val % 5 == 0){
                    new_val /= 5;
                    C::func(val);
                }
                while (new_val % 3 == 0){
                    new_val /= 3;
                    B::func(val);
                }
                while (new_val % 2 == 0){
                    new_val /= 2;
                    A::func(val);
                }
    		 }
    ...
    };
    
    -1|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy