Click here to Skip to main content
15,891,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
suppose I have the following class

C++
#ifndef TRAY_H
#define TRAY_H
#include "EGG.h";
#include "FLOUR.h";
class TRAY
{
double price;
std::vector<EGG> eggs;
public:
TRAY(int number);
~TRAY();
double getTotalPrice();
std::vector<EGG> getEggs();
};
#endif


How would I go about serializing a TRAY object's eggs inc c++ using sqlite3?

One other question I have is if it is possible to serialize an object that has no attributes, i.e. it has only functions.

Useful resources: SQLite C/C++ Tutorial
Posted
Updated 20-Nov-14 20:33pm
v3
Comments
Afzaal Ahmad Zeeshan 21-Nov-14 2:08am    
You can serialize the object; with or without any attribute or property. Where are you actually stuck?
pyler 21-Nov-14 2:14am    
Yes I was.
So in the TRAY.cpp file, eggs are pushed into the eggs vector.

I have no problems serializing an object's attributes so long as they are ints or strings, but I was stuck when it came to data structures like vectors and arrays. I thought of making variables for each object in the vector but I didn't know how to go about it.
Afzaal Ahmad Zeeshan 21-Nov-14 2:34am    
You would use templates here, since you don't know what you might be pushing into the vector.
pyler 21-Nov-14 2:53am    
Suppose I'm pushing eggs into the vector. Could you please provide an example to shed some more light on this?
[no name] 21-Nov-14 3:29am    
http://stackoverflow.com/questions/3523832/serialization-of-vectors-in-c

1 solution

You may either write your own code for serializing a vector (which in turn serializes all the items of the vector) or use, for instance, boost::serialization[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900