returning a local object is OK, the caller will get a copy of it (so make sure the copy
constructor is present and correct!).
it is returning references or pointers to locals that is trouble.

if all you want is temporary data storage, ie you don't need persistence in a database 
file, you
might find something like this much easier:

struct stuff
{
   std::string id;
   double data;
}

typedef std::vector<stuff> MyStuff;

MyStuff execute0_sub() 
{
...

shorter, more readable code, and faster to execute.


--- Riccardo Cohen <[EMAIL PROTECTED]> wrote:
> Hi,
> I would like to use storage and views to return a structured table of data instead 
> of painful
> char** 
> and double**.
> So I built a c4_Storage and return it. I'm not used to this syntax (I always use 
> pointers). Is
> it 
> safe to do that :
> 
> c4_Storage execute0_sub()
> {
>    printf("test mem only storage\n");
>    c4_Storage  sto;
>    c4_View     view=sto.GetAs("myview[id:S,data:D]");
>    c4_Row      row;
>    c4_StringProp   id("id");
>    c4_DoubleProp   data("data");
>    id(row)="one";
>    data(row)=1;
>    view.Add(row);
>    id(row)="two";
>    data(row)=2;
>    view.Add(row);
>    return(sto);
> }
> 
> void execute0()
> {
>    printf("test mem only storage\n");
>    long idx;
>    c4_Storage  sto=execute0_sub();
>    c4_View     view=sto.GetAs("myview[id:S,data:D]");
>    c4_StringProp   id("id");
>    c4_DoubleProp   data("data");
>    for (idx=0;idx<view.GetSize();idx++)
>      printf("id='%s',data=%f\n",(const char*)id(view[idx]),(double)data(view[idx]));
> }
> 
> in particular returning an object that is local to the function ???
> It works but I need confirmation
> Thanks
> 
> -- 
> Riccardo Cohen
> 
> Articque
> Les Roches
> 37230 Fondettes
> France
> web = http://www.articque.com
> tel: +33 02 47 49 90 49
> fax: +33 02 47 49 91 49
> 
> 
> _____________________________________________
> Metakit mailing list  -  [EMAIL PROTECTED]
> http://www.equi4.com/mailman/listinfo/metakit


__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
_____________________________________________
Metakit mailing list  -  [EMAIL PROTECTED]
http://www.equi4.com/mailman/listinfo/metakit

Reply via email to