scoping variables between libraries and sketches

Hello all;

I defined a struct in a library like this:
Header File:

struct srcLimits_t		// source limits for DAC and Display for each source mode
	{
	 srcLimits_t();		// a struct of arrays, 1 element for each source mode 
	 int maxVal[4];		// maximum value for DAC = 2^n - 1 where n = no. of DAC bits
	 int minVal[4];		// minimum value for DAC - depends on mode
	 uint8_t resVal[4];	// minimum mode resolution, LSD for display, divisor for DAC Value
	}

CPP File:

srcLimits_t::srcLimits_t()
   {
   /* Voltage Source */
     maxVal[0] = 1023;	//full count is 10.23V
     minVal[0] = 0;
     resVal[0] = 1;		//each count is 10mV
	 
   /* Current Source */
    maxVal[1] = 5115;	//full count is 5.115A
    minVal[1] = 0;
    resVal[1] = 5;		//each count is 5mA
	 
   /* Voltage Sink */
    maxVal[2] = 1023;	//full count is 10.23V
    minVal[2] = 100;		//1 volt minmum for voltage sink
    resVal[2] = 1;		//each count is 10mV
	 
   /* Current Sink */
    maxVal[3] = 5120;	//full count is 5.120A
    minVal[3] = 5;		//5mA minimum for current sink
    resVal[3] = 5;		//each count is 5mA
   }

I use the struct in the sketch fine by declaring:

srcLimits_t srcLimits;

everything works as expected in the sketch.

But I would like to access srcLimits within a class from the same library that the struct is defined in
The header for the Class is:

class Source {
	public:
	//constructor
	Source (byte selDAC, int ctrlDAC);
       
        int updateSrc (uint8_t valToUpdate[], int newMode, int digit, int dir);

The CPP code is:

 int Source::updateSrc (uint8_t valToUpdate[], int newMode, int digit, int dir)
.
.
 if (newVal < srcLimits.minVal[newMode] || newVal > srcLimits.maxVal[newMode]) {        
	newVal = constrain (newVal, srcLimits.minVal[newMode], srcLimits.maxVal[newMode]);

The error I get is that srcLimits is not declared within the scope of this class. Is there a way to get global variables from a sketch visible within a library class? I would rather not have to pass the values as arguments.
Thanks :confused:

I would rather not have to pass the values as arguments.

Then pass a reference to the structure.

I am curious, how would I do that?
I found this link that has a solution for me:
http://forum.arduino.cc/index.php?topic=120026.msg903135#msg903135

You basically declare the struct as an extern within the class. But how would I pass a reference?
Thx

int Source::updateSrc(

    srcLimits_t & srcLimits,  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    uint8_t valToUpdate[], int newMode, int digit, int dir)

Posting code that can actually be compiled would be a big help. Your struct definition won't compile.

Thanks all,
I will try the pointer, I need to start using those more in my code.
I am curious, though. The struct compiles OK in my library so I don't know what I missed when copying the code into the forum.

The struct compiles OK in my library so I don't know what I missed when copying the code into the forum.

Structs, like classes and arrays, need a ; after the closing }.