0

Sorry if my question is dumb, I wanted to know if there is a way to make a static function that is only available to the classes I want to, example:

class A
{
    static int add(int a, int b)
    {
        return a+b;
    }
}

class B
{
    int getInt()
    {
        return A::add(10,10); // Should return 20
    }
}

class C
{
    int getInt()
    {
        return A::add(10,10) // I don't want C class to access A::add()
    }
}

int main()
{
    B b;
    C c;
    int x = b.getInt();
    int y = c.getInt(); //Should get a error
    return 0;
}
Hassan
  • 1
  • 1
  • 2

0 Answers0