Hi,
Origin C is based on an ANSI C syntax with C++ extensions so
Origin C supports both pointers (C and C++) and references
(C++ only). In-house we often use references because of ease
of use and clarity. Your code re-written to use references is
below in the functions test and ColProc:
void test(int iCol = 0)
{
Worksheet wks = Project.ActiveLayer();
ColProc(iCol, wks);
}
void ColProc(int Index, Worksheet &sht) // Pass by reference
{
Dataset ds;
int nrows = sht.GetNumRows();
ds.Attach(sht, Index);
for(int ii = 0, jj = 1; jj <= nrows; ii++,jj++)
{
if((ds[ii] - ds[jj]) > 0.1)
{
printf("Found the break: %i\n", ii);
return;
}
}
}
One nice thing about above code is that you can just pass your
Worksheet object from the test program and not have to worry about
correctly using the address of operator & in the function call or
the pointer de-referencer in the called function as I did below
in test2 and ColProc2:
void test2(int iCol = 0)
{
Worksheet wks = Project.ActiveLayer();
ColProc2(iCol, &wks);
}
void ColProc2(int Index, Worksheet* sht) // Pass by pointer
{
Dataset ds;
int nrows = sht->GetNumRows(); // note ->
ds.Attach(*sht, Index); // note * (value of)
for(int ii = 0, jj = 1; jj <= nrows; ii++,jj++)
{
if((ds[ii] - ds[jj]) > 0.1)
{
printf("Found the break: %i\n", ii);
return;
}
}
}
I hope this helps.
Gary
OriginLab
Edited by - Gary Lane on 02/15/2005 3:50:46 PM