How to use user defined type in other function.
-
Hi, I have written a code in C++ which works on the "POINT" user defined type i.e. POINT = (x,y). I am giving input in int form, it is converting it into point might be using "template". I am retrieving these point from another function which is a header file of mine. Now the problem is, I am calling this function in NS-3 software/program, I am unable to convert this point form into integer. * Can i return more than one value from a function, because point has two values i.e. X and Y. Please help me out.
-
Hi, I have written a code in C++ which works on the "POINT" user defined type i.e. POINT = (x,y). I am giving input in int form, it is converting it into point might be using "template". I am retrieving these point from another function which is a header file of mine. Now the problem is, I am calling this function in NS-3 software/program, I am unable to convert this point form into integer. * Can i return more than one value from a function, because point has two values i.e. X and Y. Please help me out.
-
Assuming you mean the
POINT
structure[^], you could pass it back by pointer, or pass in a pointer or reference that the called function fills in.Use the best guess
Here is my some part of my code....
int my_encrypt()
{
typedef EllipticCurve<263> ec\_t; ec\_t myEllipticCurve(1,1);
ec_t::Point P = myEllipticCurve[2]; cout << "some point P = " << P << ", 2P = " << (P+P) << "\n"; int a = irand(1,myEllipticCurve.Degree()-1); ec_t::Point Pa = a*G; // public key cout << "Alice' public key Pa = " << a << "*" << G << " = " << Pa << endl;**
ec_t::Point Pk = a*Pb;
ec\_t::ffe\_t c1( m1\*Pk.x() ); ec\_t::ffe\_t c2( m2\*Pk.y() );
I need to return these three values (Pa, C1, C2) into my main function.**
-
Here is my some part of my code....
int my_encrypt()
{
typedef EllipticCurve<263> ec\_t; ec\_t myEllipticCurve(1,1);
ec_t::Point P = myEllipticCurve[2]; cout << "some point P = " << P << ", 2P = " << (P+P) << "\n"; int a = irand(1,myEllipticCurve.Degree()-1); ec_t::Point Pa = a*G; // public key cout << "Alice' public key Pa = " << a << "*" << G << " = " << Pa << endl;**
ec_t::Point Pk = a*Pb;
ec\_t::ffe\_t c1( m1\*Pk.x() ); ec\_t::ffe\_t c2( m2\*Pk.y() );
I need to return these three values (Pa, C1, C2) into my main function.**
-
Here is my some part of my code....
int my_encrypt()
{
typedef EllipticCurve<263> ec\_t; ec\_t myEllipticCurve(1,1);
ec_t::Point P = myEllipticCurve[2]; cout << "some point P = " << P << ", 2P = " << (P+P) << "\n"; int a = irand(1,myEllipticCurve.Degree()-1); ec_t::Point Pa = a*G; // public key cout << "Alice' public key Pa = " << a << "*" << G << " = " << Pa << endl;**
ec_t::Point Pk = a*Pb;
ec\_t::ffe\_t c1( m1\*Pk.x() ); ec\_t::ffe\_t c2( m2\*Pk.y() );
I need to return these three values (Pa, C1, C2) into my main function.**
then change your function:
int my_encrypt(ec_t::Point * pPa, ec_t::ffe_t * pc1, ec_t::ffe_t * pc2 )
{
//...// 'return' the values
*pPa = Pa;
*pc1 = c1;
*pc2 = c2;return 0; // or whatever is meaningful for you
}You may as well use the approach suggested by Richard, that is embed
Pa, c1, c2
into astruct
and pass the pointer to such astruct
to your function.Veni, vidi, vici.
-
then change your function:
int my_encrypt(ec_t::Point * pPa, ec_t::ffe_t * pc1, ec_t::ffe_t * pc2 )
{
//...// 'return' the values
*pPa = Pa;
*pc1 = c1;
*pc2 = c2;return 0; // or whatever is meaningful for you
}You may as well use the approach suggested by Richard, that is embed
Pa, c1, c2
into astruct
and pass the pointer to such astruct
to your function.Veni, vidi, vici.
Hi.. i have used the structure to pass three different variable as shown below... int main() { struct result t1; t1 = my_encrypt(); cout << t1.pa << t1.c1 << t1.c2 <<; } struct result my_encrypt() { typedef EllipticCurve<263> ec_t; struct result { ec_t::Point Pa; ec_t::ffe_t c1; ec_t::ffe_t c2; }t; ec_t::Point Pk = a*Pb; ec_t::ffe_t t.c1( m1*Pk.x() ); ec_t::ffe_t t.c2( m2*Pk.y() ); return (t); } I am getting so many errors.. Please tell me anything wrong declaration here. Can i declare that structure as global...
-
Hi.. i have used the structure to pass three different variable as shown below... int main() { struct result t1; t1 = my_encrypt(); cout << t1.pa << t1.c1 << t1.c2 <<; } struct result my_encrypt() { typedef EllipticCurve<263> ec_t; struct result { ec_t::Point Pa; ec_t::ffe_t c1; ec_t::ffe_t c2; }t; ec_t::Point Pk = a*Pb; ec_t::ffe_t t.c1( m1*Pk.x() ); ec_t::ffe_t t.c2( m2*Pk.y() ); return (t); } I am getting so many errors.. Please tell me anything wrong declaration here. Can i declare that structure as global...
Quote:
int main() { struct result t1; t1 = my_encrypt();
Should be:
int main()
{
struct result t1 = {0};my\_encrypt(&t1); //..
Quote:
struct result my_encrypt() {
should be:
int my_encrypt(struct result * pt1)
{
// ...Please note, there are other (unrelated) errors in your code.
Veni, vidi, vici.