The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 vector of user-defined structure

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
pierremx Posted - 01/23/2008 : 5:22:01 PM
Hello,

In Origin 8, is it possible to declare vector of user-defined structure ?

Thank you,
Pierre.
2   L A T E S T    R E P L I E S    (Newest First)
pierremx Posted - 01/24/2008 : 05:51:47 AM
Thank you for your help.
In my case I will use malloc...

Regards,
Pierre.
cpyang Posted - 01/24/2008 : 04:47:49 AM
Sorry, Origin 8 does not have much change in terms of Origin C.

You have to use malloc and free, but can wrap in a nice class, as shown below:
 
struct myTest {
double a;
int n;
};

class MyTestVector
{
public:
MyTestVector(int nn)
{
m_nSize = nn;
m_p = (myTest*) malloc(m_nSize * sizeof(myTest));
}
~MyTestVector()
{
free(m_p);
}
int GetSize() {return m_nSize;}
myTest* GetData() {return m_p;}
myTest* GetAt(int n) {
if(n >=0 && n < m_nSize)
return m_p[n];

return NULL;
}
private:
int m_nSize;
myTest* m_p;
};


void test(int nn = 5)
{
MyTestVector junk(nn);

for(int ii = 0; ii < junk.GetSize(); ii++)
{
myTest* pp = junk.GetAt(ii);
pp->a = ii*0.01;
pp->n = ii;
}

for(ii = 0; ii < junk.GetSize(); ii++)
{
myTest* pp = junk.GetAt(ii);
printf("val=%g, index = %d\n", pp->a, pp->n);
}
}




CP



The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000