Linking Class Variable in Different Source Code Together

Hi...

I am wondering is there any way linking to two variable together?

For example, in source code A, I have a TinyGPSPlus class object and I have another TinyGPSPlus class object in source code B. Is there any method to link both of them together? I meant whenever the object is called, it should be referred to the same object.

I meant whenever the object is called, it should be referred to the same object.

They can't be the same object if you are defining two instances of the TinyGPSPlus class.

You can define one instance in one file, and share that instance with another file.

Exactly how depends on your code, which seems to have disappeared from your post.

Navigation.h

#include "TinyGPS++.h"

#ifndef _NAVIGATION_h
#define _NAVIGATION_h

#if defined(ARDUINO) && ARDUINO >= 100
	#include "arduino.h"
#else
	#include "WProgram.h"
#endif

extern TinyGPSPlus theGPS;
extern double theLat;
extern double theLong;
extern double nextLat;
extern double nextLong;

void ReadNowCoord();




#endif

Navigation.cpp

#include "Navigation.h"


void InitializeNavg()
{
	theGPS = TinyGPSPlus();

}

void ReadNowCoord()
{
	if (theGPS.location.isValid() && theGPS.location.isUpdated())
	{
		theLong = theGPS.location.lng();
		theLat = theGPS.location.lat();
	}
}

Main.cpp

void setup()
{

  theLat=theGPS.location.lat();
}

Main.cpp

TinyGPSPlus theGPS;
double theLat;
double theLong;
double nextLat;
double nextLong;

void setup()
{
  theLat=theGPS.location.lat();
}

Navigation.h

extern TinyGPSPlus theGPS;
extern double theLat;
extern double theLong;
extern double nextLat;
extern double nextLong;

void ReadNowCoord();

Navigation.cpp

#include "Navigation.h"
void InitializeNavg()
{
	theGPS = TinyGPSPlus();

}

void ReadNowCoord()
{
	if (theGPS.location.isValid() && theGPS.location.isUpdated())
	{
		theLong = theGPS.location.lng();
		theLat = theGPS.location.lat();
	}
}

Is it the way of declaring it?

Main should NOT be used as the name of a sketch.

How is Main.cpp supposed to know anything about the one instance of TinyGPSPlus that Navigation.cpp creates?

In your newer code, you create an instance of TinyGPSPlus in the Main.cpp and another one in the InitializeNavg() function that is not defined in the Navigation.h file.

Why?

PaulS:
In your newer code, you create an instance of TinyGPSPlus in the Main.cpp and another one in the InitializeNavg() function that is not defined in the Navigation.h file.

Why?

Oops.. I forgot to include the InitializeNavg() into the Navigation.h file.
If assumed that InitializeNavg() is included, can i construct the instance of TinyGPSPlus in the Navigation.cpp? Or I should just construct the instance in the Main?
Because the amount of hardware module that I am dealing is a bit too much for me so I am planning to group all the module related function into a .cpp file.

It is far simpler to create the instance of TinyGPSPlus in the sketch, and pass the instance to the functions that need access to it.