Function is inaccessible

c++

Solution

The default protection level for a `class` in C++ is `private` (with the others being `public` and `protected`). That means all your members and your member function are private and only accessible by other member functions of that class or friends (functions or classes) of that class.

The function main is neither and you end up with the error.

C++ provides a handy shortcut (or C legacy cruft, depending on your worldview) called `struct`, where the default protection level is `public`.

class my_class {
public:
  int my_int;      
};

or

struct my_struct {
  int my_int;
};

should show the difference.

Problem

I have ``` // file BoardInitializer.h #include <stdio.h> #include <tchar.h> #include <string> #include <iostream> using namespace std; class BoardInitializer { static int *beginBoard; static int *testBoard; static void testBoardInitialize(); } // file mh.cpp #include "BoardInitializer.h" int main(int argc, char* argv[]) { BoardInitializer.testBoardInitialize(); return 0; } ``` and I implemented `BoardInitializer::testBoardInitialize` in `mh.cpp`. But I get the error "Function is inaccessible". What's wrong?

Original source