joli 0 Report post Posted July 29, 2016 (edited) This is just an example for who needs something alike also to c++ experts comments that are very welcome.Purpose: .create a list of objects and do something with them Device: pic18Fxxx // file: students.h #ifndef _STUDENTS_H_ #define _STUDENTS_H_ typedef unsigned char uchar; #define STUDENTS 64 // max number of students class Student // { private: uchar s_id; // data member uchar s_age; // data member public: void AddStudent( uchar *pustudent ); // function member }; extern Student StuList[ STUDENTS ]; // studets list #endif // file: student.cpp #include <system.h> #include "students.h" class Student StuList[STUDENTS]; // list of students void Student::AddStudent( uchar *pstudent ) // AddStudent { s_id = *pstudent++; // update id s_age = *pstudent; // update age } void main() { uchar adata[2]; // buffer from where data comes from for( uchar i=0; i<STUDENTS; i++ ) // Lets fill all students [0..63] { adata[0] = i+1; // data to be stored adata[1] = i+1; StuList[i].AddStudent( adata ); // add student id&age } while(1); } i did AddStudent member this way because i needed to pass a buffer with data received from the serial port. It works perfect, but suggestions are welcome. I also did it with an array of structures that results shorter in ram resources. Using classes an additional byte is consumed for each element. br Edited July 31, 2016 by joli Quote Share this post Link to post Share on other sites
joli 0 Report post Posted July 31, 2016 Forgot to mention the basis of it is on boostc++ manual page 83. br Quote Share this post Link to post Share on other sites