Question: How would I go about doing something like this?

header.h

```
 struct myStruct;
 extern myStruct array[];

```

main.cpp

```
#include "header.h"
struct myStruct{
int a = 0;
};
myStruct array[5];
array[0].a = 1;

```

file2.cpp

```
#include "header.h"
std::cout << array[0].a;

```

Answer: 
Well, first of all you should put `struct` declarations in the header files.

Second, you can't put assignments to arrays or `std::cout` statements just loose in files. I'm assuming you did this for short code and not because you didn't know it needed to be in a function, but I'm pointing it out just in case.

Third, struct declarations require a semicolon

What you would do is have a header file:

header.hpp:

```
#pragma once

struct MyStruct {
    int a = 0;
};

extern MyStruct array[5];

```

The `extern` here means that the data is somewhere else. So let's make the somewhere else.

header.cpp:

```
#include "header.hpp"

MyStruct array[5];

```

main.cpp:

```
#include "header.hpp"

void someFunction() {
    ...
    array[0].a = 1;
    ...
}

```

file2.cpp:

```
#include <iostream>
#include "header.hpp"

void someOtherFunction() {
    ...
    std::cout << array[0].a;
    ...
}

```
> 
> How would I go about doing something like this?
> 
> 
> 

You could go about doing something like what you did by doing something like what you did, except fixing the bugs in your attempt. Here is the list of bugs:

* You failed to end the definition of `myStruct` with a semicolon.
* `.c` suffix is conventionally for C source files while you're writing C++. Your compiler will likely be confused unless you provide some unconventional options to the compiler.
* You use `cout` which you forgot to declare. Or did you intend to use `std::cout`? In that case you must include `<iostream>` in order to use it, and use the appropriate namespace.
* In `file2.c`, you use the class `myStruct` in a way that depends on the definition of `myStruct` without providing that definition.
* `array[0].a = 1;` and `cout << array[0].a;` are expression statements. Expression statements may not be in namespace scope, and must be within a block scope. In your program, those expression statements are in the namespace scope which makes the program ill-formed.