Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to use user defined type in other function.

How to use user defined type in other function.

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++tutorial
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Manoj7390
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • M Manoj7390

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • L Lost User

        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

        M Offline
        M Offline
        Manoj7390
        wrote on last edited by
        #3

        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.**

        L CPalliniC 2 Replies Last reply
        0
        • M Manoj7390

          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.**

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Sorry, but you lost me at typedef EllipticCurve<263> ec_t;.

          Use the best guess

          1 Reply Last reply
          0
          • M Manoj7390

            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.**

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            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 a struct and pass the pointer to such a struct to your function.

            Veni, vidi, vici.

            In testa che avete, signor di Ceprano?

            M 1 Reply Last reply
            0
            • CPalliniC CPallini

              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 a struct and pass the pointer to such a struct to your function.

              Veni, vidi, vici.

              M Offline
              M Offline
              Manoj7390
              wrote on last edited by
              #6

              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...

              CPalliniC 1 Reply Last reply
              0
              • M Manoj7390

                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...

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #7

                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.

                In testa che avete, signor di Ceprano?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups