0

How do I know what will be executed, operator() or static function. Although I thought that static can only stay in class, what is this static modifier doing?

#include <iostream>
using namespace std;

class A {
private:
    int i;
public:
    A(int ii) { i = ii; }
    int dohvati() { return i; }
    int operator()() { return 3; }
};
static int a() { return 4; }

int main() {
    A a(2);
    cout << a();
    return 0;
}

1 Answers1

3

You can check this out to see what static non-class functions are. As far as your code goes, I think that the scope is playing the main role here. Instance a of class A is in the current scope so it is chosen over method a() which is in the global scope.

Shahriar
  • 768
  • 4
  • 11