0

I have a structure defined in main.cpp file and i want that same structure with value to be visible in other cpp file.
I tried this and this is way out of understanding for me as a beginner. So i re-ask the initial question again but in a simple way.

main.cpp

#include<iostream>

extern struct abc
{
    int a;
    std::string bla_bla;
};

void display(abc (&)[2]);

int main(void)
{
    abc put[2];
    put[0] = {10,"Apple"};
    put[1] = {20,"Ball"};
    display(put);
}

other.cpp

#include <iostream>

extern abc;

void display(abc (&put)[2])
{
    std::cout << put[0].a << '\t' << put[0].bla_bla << std::endl;
    std::cout << put[1].a << '\t' << put[1].bla_bla << std::endl;
}

it shows error a storage class can only be specified for objects and functions
and i am using c++17
is there any way to make that one structure visible to every cpp?
thanks in advance

EDIT: I got it need to keep the struct in .h file

0 Answers0