Accessing a static array in class by using overloaded operator ()
<p>I'm new here so I hope I will write understandable question.</p>

<p>My problem is, how to access a static array in class by using overloaded operator ().</p>

<p>Main.cpp:</p>

<pre><code>class SomeClass
{
public:
    static const int a[2][2];

    const int&amp; operator() (int x, int y) const;
};
</code></pre>

<p>Just under it, I define the array a:</p>

<pre><code>const int SomeClass::a[2][2] = {{ 1, 2 }, { 3, 4 }};
</code></pre>

<p>Here is the overloaded operator:</p>

<pre><code>const int&amp; SomeClass::operator() (int x, int y) const
{
    return a[x][y];
}
</code></pre>

<p>In main(), I want to access 'a' 2D array just by using <code>SomeClass(1, 1)</code> which shloudl return 4. But when I try to compile main like this:</p>

<pre><code>int main(void)
{
    cout &lt;&lt; SomeClass(1, 1) &lt;&lt; endl;

    return 0;
}
</code></pre>

<p>I get this error:</p>

<pre><code>PretizeniOperatoru.cpp: In function ‘int main()’:
PretizeniOperatoru.cpp:22:22: error: no matching function for call to ‘Tabulka::Tabulka(int, int)’
PretizeniOperatoru.cpp:22:22: note: candidates are:
PretizeniOperatoru.cpp:5:7: note: SomeClass::SomeClass()
PretizeniOperatoru.cpp:5:7: note:   candidate expects 0 arguments, 2 provided
PretizeniOperatoru.cpp:5:7: note: SomeClass::SomeClass(const SomeClass&amp;)
PretizeniOperatoru.cpp:5:7: note:   candidate expects 1 argument, 2 provided
</code></pre>

<p>I realised I don't know, where is the problem. It seems that there is called a constructor of the class. It seems that I'm constructing the class instead of accessing the array.</p>

<p>What does it mean? Is there any way to do the array like this or it would be better to break rules of encapsulation and define it as global? Does it mean, that overloaded operators cannot be used to access static arrays?</p>

<p>When I do it this way, it compiles OK:</p>

<pre><code>int main(void)
{
    SomeClass class;
    cout &lt;&lt; class(1, 1) &lt;&lt; endl;

    return 0;
}
</code></pre>

<p>Thanks for response and hope my problem makes sense. I didn't use [] operator for accessing, because it is more hard to implement than ( ).</p>
