Sharing a c++ structure between multiple files?

Hello,

I am trying to create a structure that I access from a .cpp library file and a .ino(new file ext for pde, created in arduino ide). The structure will have a few variables that I will need to set/get in the myfile.pde and the mylibraryfile.cpp files. Should I define the structure in another .h file, something like mystructure.h? I would like to initialize the structure in the mylibraryfile.cpp file. Currently, my files look like this. Can anyone provide assistance on how to do this?

myfile.ino
mylibraryfile.h
mylibraryfile.cpp

Thanks,

-ren

the .h should contain the structure declaration,
the .cpp should contain the structures function definitions.

Your .ino file should create the object instance.

.h

struct MyStruct{

  int DataFunc( void );
  int i_Data;
};

void DoStuff( MyStruct &m_Struct );

.cpp

int MyStruct::DataFunc( void )
  {
    return this->i_Data;
  }

void DoStuff( MyStruct &m_Struct )
  {
    //Do Stuff with structure
    return;
  }

.ino

#include "my.h"

//Create structure instance.
MyStruct m_StructureVariable;

void setup()
  {
    //Use structure
    int i_Val = m_StructureVariable.Data();

    DoStuff( m_StructureVariable );
    return;
  }
void loop(){}

pYro_65,

Thanks for the info, but there is no way to create the object instance inside the mylibraryfile.cpp file and still access in the .ino file? I will have includes mylibraryfile.h in the .ino file. What is it a problem?

Thanks,

-ren

but there is no way to create the object instance inside the mylibraryfile.cpp file and still access in the .ino file?

Sure, there is. Create the instance in the .cpp file. You will need to tell the sketch that the structure is extern(al) to the sketch file, so there really isn't much advantage in initializing the structure in the cpp file.