Question: So I need my objects to be able to use functions that are within the main class, so when they are created I want them to get it through their parameters.

```
int main(int argc, char* args[])
    {
    Unit units[3]={{5,5,this},{8,8,this},{12,12,this}};
    units[0].init(true);
    for (int i=1;i<sizeof(units) / sizeof(units[0]);i++) {
        units[i].init(false);
    }

```

Where i put "this" it should be the main class, this is how I would do it in java but I am unsure how to do it here. I tried "\*this" and "this" but all I get is an error: 
Invalid use of 'this' in non-member function. 
Searching for the error gave me nothing to work with since I am rather unknowing on c++'s class systems.

The two first parameters are for the location. The Init commands parameter sets whether they are allies or not. 

I want the Unit classes to be able to access:

```
int getClosestHostileX(int ask_x,int ask_y,bool team) {
    return 55;
}

```

There is supposed to be more code here later I am just trying to get them to return.

I am using Code::Blocks IDE and GNU GCC compiler.

TL;DR How do I make my other classes access functions from my main class?

Answer: 
You couldn't do that in Java, either. In Java, the entrypoint is a static method and has no associated object instance.

The solution is the same -- instantiate your type.

```
int main(int argc, char** argv)
{
   MainClass main_object; // creates an instance
   Unit units[3]={{5,5,&main_object},{8,8,&main_object},{12,12,&main_object}};
   units[0].init(true);
   for (int i=1;i<sizeof(units) / sizeof(units[0]);i++) {
      units[i].init(false);
}

```
c++ isn't like java. You don't need to have all of your methods(or functions as they're called in c++) inside a class. 

`main` is a function, not a class. there is no `this`

Now you can have global variables, or you can put variables/objects on the heap, for other classes to be able to use, but in general, c# doesn't actually have a Main class.