Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. C++ struct function with return struct ...
Forum Updated to NodeBB v4.3 + New Features

C++ struct function with return struct ...

Scheduled Pinned Locked Moved Solved C++ Gurus
22 Posts 5 Posters 10.9k 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
    mrjj
    Lifetime Qt Champion
    wrote on 27 Sept 2016, 09:28 last edited by mrjj
    #2

    Hi
    A struct is a type
    and it will not just convert between them.

    Your naming of the structs is very verbose and hard to read & understand as you make
    the type look like function name.

    it seems you define
    Find_Angle_Central_Point_Targhet Find_A_Cent_P(xx)

    so return type is Find_Angle_Central_Point_Targhet
    and in the function you define
    Get_Angle_Central_Point_Targhet Get_A_Cent_P;
    return Get_A_Cent_P; << this is not correct type to return.

    G 1 Reply Last reply 27 Sept 2016, 10:06
    1
    • M mrjj
      27 Sept 2016, 09:28

      Hi
      A struct is a type
      and it will not just convert between them.

      Your naming of the structs is very verbose and hard to read & understand as you make
      the type look like function name.

      it seems you define
      Find_Angle_Central_Point_Targhet Find_A_Cent_P(xx)

      so return type is Find_Angle_Central_Point_Targhet
      and in the function you define
      Get_Angle_Central_Point_Targhet Get_A_Cent_P;
      return Get_A_Cent_P; << this is not correct type to return.

      G Offline
      G Offline
      gfxx
      wrote on 27 Sept 2016, 10:06 last edited by
      #3

      @mrjj ok I suspect these ... I understand not possible return other struct type .... but I can define these struct and use these struct func?:

      struct a{
      int x;
      double y;
      cv::Point cerr0;
      cv::Point cerr1;
      cv::Point cerr2;
      cv::Point cerr3;
      }
      
      ........
      
      a afunc (cv::Point cerr0){  /* <---------- no pass all value of a struct only one .... but return all*/
      /*my operation .....*/
      afunc.x = some_value0;
      afunc.y = some_value1;
      afunc.cerr0 = some_value0;
      afunc.cerr1 = some_value1;
      afunc.cerr2 = some_value2;
      afunc.cerr3 = some_value3;
      
      return afunc;
      }
      
      These is valid use of struct func??
      
      regards
      Giorgio
      
      
      
      
      

      bkt

      J 1 Reply Last reply 27 Sept 2016, 10:41
      0
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 27 Sept 2016, 10:11 last edited by
        #4

        Yes, thats correct but its a type so it wont convert.

        so if you say

        struct A;
        struct B;

        A myfunc() {
        A mine;
        return mine; // ok correct type
        }

        A myfunc() {
        B mine;
        return mine; // error B is not A type
        }

        1 Reply Last reply
        1
        • G gfxx
          27 Sept 2016, 10:06

          @mrjj ok I suspect these ... I understand not possible return other struct type .... but I can define these struct and use these struct func?:

          struct a{
          int x;
          double y;
          cv::Point cerr0;
          cv::Point cerr1;
          cv::Point cerr2;
          cv::Point cerr3;
          }
          
          ........
          
          a afunc (cv::Point cerr0){  /* <---------- no pass all value of a struct only one .... but return all*/
          /*my operation .....*/
          afunc.x = some_value0;
          afunc.y = some_value1;
          afunc.cerr0 = some_value0;
          afunc.cerr1 = some_value1;
          afunc.cerr2 = some_value2;
          afunc.cerr3 = some_value3;
          
          return afunc;
          }
          
          These is valid use of struct func??
          
          regards
          Giorgio
          
          
          
          
          
          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 27 Sept 2016, 10:41 last edited by
          #5

          @gfxx said in C++ struct function with return struct ...:

          a afunc (cv::Point cerr0){ /* <---------- no pass all value of a struct only one .... but return all*/
          /my operation ...../
          afunc.x = some_value0;
          afunc.y = some_value1;
          afunc.cerr0 = some_value0;
          afunc.cerr1 = some_value1;
          afunc.cerr2 = some_value2;
          afunc.cerr3 = some_value3;

          return afunc;
          }

          This does not make any sense. You probably mean:

          a afunc (cv::Point cerr0){
              /*my operation .....*/
              a result;
              result.x = some_value0;
              result.y = some_value1;
              result.cerr0 = some_value0;
              result.cerr1 = some_value1;
              result.cerr2 = some_value2;
              result.cerr3 = some_value3;
          
              return result;
          }
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply 27 Sept 2016, 12:26
          1
          • J jsulm
            27 Sept 2016, 10:41

            @gfxx said in C++ struct function with return struct ...:

            a afunc (cv::Point cerr0){ /* <---------- no pass all value of a struct only one .... but return all*/
            /my operation ...../
            afunc.x = some_value0;
            afunc.y = some_value1;
            afunc.cerr0 = some_value0;
            afunc.cerr1 = some_value1;
            afunc.cerr2 = some_value2;
            afunc.cerr3 = some_value3;

            return afunc;
            }

            This does not make any sense. You probably mean:

            a afunc (cv::Point cerr0){
                /*my operation .....*/
                a result;
                result.x = some_value0;
                result.y = some_value1;
                result.cerr0 = some_value0;
                result.cerr1 = some_value1;
                result.cerr2 = some_value2;
                result.cerr3 = some_value3;
            
                return result;
            }
            
            G Offline
            G Offline
            gfxx
            wrote on 27 Sept 2016, 12:26 last edited by
            #6

            @jsulm said in C++ struct function with return struct ...:

            @gfxx said in C++ struct function with return struct ...:

            a afunc (cv::Point cerr0){ /* <---------- no pass all value of a struct only one .... but return all*/
            /my operation ...../
            afunc.x = some_value0;
            afunc.y = some_value1;
            afunc.cerr0 = some_value0;
            afunc.cerr1 = some_value1;
            afunc.cerr2 = some_value2;
            afunc.cerr3 = some_value3;

            return afunc;
            }

            This does not make any sense. You probably mean:

            a afunc (cv::Point cerr0){
                /*my operation .....*/
                a result;
                result.x = some_value0;
                result.y = some_value1;
                result.cerr0 = some_value0;
                result.cerr1 = some_value1;
                result.cerr2 = some_value2;
                result.cerr3 = some_value3;
            
                return result;
            }
            

            You are perfectly in right .... but anyhow the function is write in my file.h and I would reuse it in file.ccp ... but if in file.cpp i write:

             afunc (cv::Point myvalue);
            
            /* I expect to be able to write these:*/
            
            myvar1 = result.x;
            myvar2 = result.y;
            etc. etc....
            
            /*but these is not possible .... or qt not permit it*/
            

            Regards
            Giorgio

            bkt

            1 Reply Last reply
            0
            • m.sueM Offline
              m.sueM Offline
              m.sue
              wrote on 27 Sept 2016, 12:35 last edited by
              #7

              Hi,
              "result" is a local variable in "afunc". You cannot expect it to be known outside of "afunc". This is no restriction of Qt but a feature of the C++ language. But you can write something like this:

              a result=afunc(myvalue);
              myvar1 = result.x;
              myvar2 = result.y;
              

              -Michael.

              G 1 Reply Last reply 27 Sept 2016, 12:52
              1
              • m.sueM m.sue
                27 Sept 2016, 12:35

                Hi,
                "result" is a local variable in "afunc". You cannot expect it to be known outside of "afunc". This is no restriction of Qt but a feature of the C++ language. But you can write something like this:

                a result=afunc(myvalue);
                myvar1 = result.x;
                myvar2 = result.y;
                

                -Michael.

                G Offline
                G Offline
                gfxx
                wrote on 27 Sept 2016, 12:52 last edited by gfxx
                #8

                @m.sue Tanks A lot I have just read in an ebook this peculiarity of the struct .... I have many elements struct each one with a calculation and a return .... something like these:

                struct a{
                int x;
                double y;
                cv::Point cerr0;
                cv::Point cerr1;
                cv::Point cerr2;
                cv::Point cerr3;
                cv::Point result1() { return /* some long calculation*/};
                cv::Point result2() {return  /* some long calculation*/};
                cv::Point result3() {return  /* some long calculation*/};
                
                }
                
                ........
                
                afunc (cv::Point cerr0){  /* so in my file.cpp i can write these*/
                some_value0 = afunc.result1;
                some_value1 = afunc.result2;
                some_value2 = afunc.result3;
                
                

                In my case I think is a little bit more long as I expect .... :( ..so I try your suggest to try to simplify my function ...

                Regards
                Giorgio

                bkt

                G 1 Reply Last reply 27 Sept 2016, 13:31
                0
                • G gfxx
                  27 Sept 2016, 12:52

                  @m.sue Tanks A lot I have just read in an ebook this peculiarity of the struct .... I have many elements struct each one with a calculation and a return .... something like these:

                  struct a{
                  int x;
                  double y;
                  cv::Point cerr0;
                  cv::Point cerr1;
                  cv::Point cerr2;
                  cv::Point cerr3;
                  cv::Point result1() { return /* some long calculation*/};
                  cv::Point result2() {return  /* some long calculation*/};
                  cv::Point result3() {return  /* some long calculation*/};
                  
                  }
                  
                  ........
                  
                  afunc (cv::Point cerr0){  /* so in my file.cpp i can write these*/
                  some_value0 = afunc.result1;
                  some_value1 = afunc.result2;
                  some_value2 = afunc.result3;
                  
                  

                  In my case I think is a little bit more long as I expect .... :( ..so I try your suggest to try to simplify my function ...

                  Regards
                  Giorgio

                  G Offline
                  G Offline
                  gfxx
                  wrote on 27 Sept 2016, 13:31 last edited by
                  #9

                  @gfxx ...NOT WORK ...

                  my real code:

                  /******************in my file.h*-***********************/
                  
                   FindAngleCPointTarghet FindCentPoint( cv::Point2f Square_Points[4], bool a, bool b, bool c, bool d)
                      {
                  
                          FindAngleCPointTarghet FindTarghet;
                  
                          F_lung1 = 0;
                          F_lung2 = 0;
                          F_lung3 = 0;
                          F_lung4 = 0;
                          F_lung5 = 0;
                          F_barix = 0;
                          F_bariy = 0;
                          F_intbarix = 0;
                          F_intbariy = 0;
                          F_bariangle = 0;
                          bool choose0 = false, choose1 = false, choose2 = false, choose3 = false;
                  
                          F_lung1 = std::pow((std::pow((Square_Points[0].x - Square_Points[1].x),2) + std::pow((Square_Points[0].y - Square_Points[1].y),2)), 0.5);
                          F_lung2 = std::pow((std::pow((Square_Points[1].x - Square_Points[2].x),2) + std::pow((Square_Points[1].y - Square_Points[2].y),2)), 0.5);
                  
                          if (F_lung2 > F_lung1)
                          {
                              F_lung3 = F_lung2;
                              F_lung4 = std::pow((std::pow((-Square_Points[1].x + Square_Points[2].x),2) + std::pow((0),2)), 0.5);
                              F_lung5 = std::pow((std::pow((-Square_Points[1].y + Square_Points[2].y),2) + std::pow((0),2)), 0.5);
                              F_barix = ((Square_Points[0].x + Square_Points[1].x + Square_Points[2].x + Square_Points[3].x)/4);
                              F_bariy = ((Square_Points[0].y + Square_Points[1].y + Square_Points[2].y + Square_Points[3].y)/4);
                              F_intbarix = round(F_barix);
                              F_intbariy = round(F_bariy);
                              F_bariangle = (std::atan2((Square_Points[2].y - Square_Points[1].y),(Square_Points[2].x - Square_Points[1].x))*180.00/3.1415926535);
                              F_centrale = cv::Point(F_intbarix, F_intbariy);
                              F_bariangle_template = F_bariangle;
                              if(a)
                              {
                  
                  ..................
                  /*the calculation proceed for 180 row with the same variable declared here ... the result ( FindTarghet.Get_centrale etc)  value change if a-b or a-d or etc etc bool value is true or false ....*/
                  ..................
                  
                          FindTarghet.Get_centrale = F_centrale;
                          FindTarghet.Get_mezzo_rect_risc = F_mezzo_rect_risc;
                          FindTarghet.Get_mezzo_rect_risc1 = F_mezzo_rect_risc1;
                          FindTarghet.Get_mezzo_rect_risc_pt2 = F_mezzo_rect_risc_pt2;
                          FindTarghet.Get_mezzo_rect_risc_pt3 = F_mezzo_rect_risc_pt3;
                          FindTarghet.X_Point = F_intbarix;
                          FindTarghet.Y_point = F_intbariy;
                          FindTarghet.Angle = F_bariangle_template;
                          FindTarghet.Major_Side1 = false;
                          FindTarghet.Major_Side2 = false;
                          FindTarghet.Get_Upper_Half_Square  = false;
                          FindTarghet.Get_Lower_Half_Square = false;
                  
                          return FindTarghet;
                  
                  
                  /* than in my file.ccp*******************/
                  
                  FindAngleCPointTarghet TarghetResutl = FindCentPoint(rect_points, targhet_verticale, targhet_orizzontale);
                  centrale =  TarghetResutl.Get_centrale;
                  mezzo_rect_risc = TarghetResutl.Get_mezzo_rect_risc;
                  mezzo_rect_risc1 = TarghetResutl.Get_mezzo_rect_risc1;
                  mezzo_rect_risc_pt2 = TarghetResutl.Get_mezzo_rect_risc_pt2;
                  mezzo_rect_risc_pt3 = TarghetResutl.Get_mezzo_rect_risc_pt3;
                  intbarix = TarghetResutl.X_Point;
                  intbariy = TarghetResutl.Y_point;
                  bariangle = TarghetResutl.Angle;
                  
                  /***********the error .... 380 error signed .... a memeory allocation id/name problem I think****************/
                  (.bss+0x120):-1: error: multiple definition of `F_lung4'
                  (.bss+0x128):-1: error: multiple definition of `F_lung3' .... etc etc.... all identical error but for all variable used during calculation ....
                  
                      }
                  

                  I'm explain my better ... I try to make in file.h a struct function with struct return value .... As you see

                  bkt

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 27 Sept 2016, 13:57 last edited by mrjj
                    #10

                    If you include data in .h file, you can get this error
                    multiple definition of XXX

                    Im not sure why this is so complex.

                    --
                    MYS.h

                    struct MyStruct { // DEFINE
                    int Value;
                    };

                    MyStruct MyFunc(); // DEFINE

                    --
                    MYS.cpp

                    MyStruct MyFunc() { // IMPLEMENT
                    MyStruct localcopy;
                    localcopy.Value=100;
                    return localcopy;
                    }

                    -- in some file--
                    #include "MYS.h"

                    void buttonClick() {
                    MyStruct usedhere = MyFunc(); // USING

                    }

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      gfxx
                      wrote on 27 Sept 2016, 14:29 last edited by gfxx
                      #11

                      MYS = MYQThread so....

                      --
                       MYQThread .h
                      
                      struct MyStruct { // DEFINE
                      int Value;
                      };
                      /* now I try to do these*/
                      MyStruct MyFunc(with  parameter){some calculation with pnota bene arameter and some other local variable}; // DEFINE
                      --
                       MYQThread .cpp
                      
                      MyStruct MyFunc() { // IMPLEMENT /* so your answer is : " in these local copy make your calculation" ... is right?*/
                      MyStruct localcopy;
                      localcopy.Value=100;
                      return localcopy;
                      }
                      
                      -- in these  MYQThread.cpp-- /* but my file.h and file.cpp is the same so is not possible do these ....*/
                      #include " MYQThread .h"
                      
                      void buttonClick() {
                      MyStruct usedhere = MyFunc(); // USING
                      
                      }
                      

                      If I understand well your reply you think mi struct function is utilize in other part of my app ... but is define in QThread.h and implement + utilized in QThread.cpp

                      Regards
                      Giorgio

                      Note:
                      @mrjj perhaps your answer sounds like you'd better build a class that a struct func ....

                      bkt

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 27 Sept 2016, 14:57 last edited by mrjj
                        #12

                        make sure that
                        MYQThread .cpp

                        MyStruct MyFunc(same params as in .h) {...}

                        No sure i understand
                        /* but my file.h and file.cpp is the same so is not possible do these*/

                        why is file.cpp and file.h the same?

                        Also for the use

                        void buttonClick() {
                        MyStruct usedhere = MyFunc( ACTUAL PARAMETERS); // USING

                        }

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          gfxx
                          wrote on 27 Sept 2016, 16:14 last edited by
                          #13
                          /***********MYQThread .h*****************/
                          
                          struct FindACPTarghet{
                              cv::Point2f Square_Points[4];
                              bool Find_Upper_Half_Square;
                              bool Find_Lower_Half_Square;
                              cv::Point Get_centrale;
                              cv::Point Get_mezzo_rect_risc;
                              cv::Point Get_mezzo_rect_risc1;
                              cv::Point Get_mezzo_rect_risc_pt2;
                              cv::Point Get_mezzo_rect_risc_pt3;
                              double X_Point;
                              double Y_point;
                              double Angle;
                              bool Major_Side1;
                              bool Major_Side2;
                              bool Get_Upper_Half_Square;
                              bool Get_Lower_Half_Square;
                              //Get_Angle_Central_Point_Targhet GetDataTarghet;
                          }/*FindCentPoint*/;
                          
                          class datathread : public QThread
                          {
                                  Q_OBJECT
                          public:
                              explicit datathread(QObject *parent = 0, bool bthw = false);
                              void run();
                              bool Stop;
                          
                              FindACPTarghet FindCentPoint( cv::Point2f Square_Points[4], bool Find_Upper_Half_Square, bool Find_Lower_Half_Square);
                          
                          /***********MYQThread .cpp*****************/
                          
                          FindACPTarghet FindCentPoint( cv::Point2f Square_Points[4], bool Find_Upper_Half_Square, bool Find_Lower_Half_Square)
                          {
                          
                              FindACPTarghet FindTarghet;  <----------------------------------------
                          
                              F_lung1 = 0;
                              F_lung2 = 0;
                              F_lung3 = 0;
                              F_lung4 = 0;
                              F_lung5 = 0;
                              F_barix = 0;
                              F_bariy = 0;
                              F_intbarix = 0;
                              F_intbariy = 0;
                              F_bariangle = 0;
                              bool choose0 = false, choose1 = false, choose2 = false, choose3 = false;
                          
                              F_lung1 = std::pow((std::pow((Square_Points[0].x - Square_Points[1].x),2) + std::pow((Square_Points[0].y - Square_Points[1].y),2)), 0.5);
                              F_lung2 = std::pow((std::pow((Square_Points[1].x - Square_Points[2].x),2) + std::pow((Square_Points[1].y - Square_Points[2].y),2)), 0.5);
                          
                              if (F_lung2 > F_lung1)
                              {..................
                          ........................
                          
                              FindTarghet.Get_centrale = F_centrale;  <--------------------------------- /*******************************undefined error reference**********************/
                              FindTarghet.Get_mezzo_rect_risc = F_mezzo_rect_risc;
                              FindTarghet.Get_mezzo_rect_risc1 = F_mezzo_rect_risc1;
                              FindTarghet.Get_mezzo_rect_risc_pt2 = F_mezzo_rect_risc_pt2;
                              FindTarghet.Get_mezzo_rect_risc_pt3 = F_mezzo_rect_risc_pt3;
                              FindTarghet.X_Point = F_intbarix;
                              FindTarghet.Y_point = F_intbariy;
                              FindTarghet.Angle = F_bariangle_template;
                              FindTarghet.Major_Side1 = false;
                              FindTarghet.Major_Side2 = false;
                              FindTarghet.Get_Upper_Half_Square  = false;
                              FindTarghet.Get_Lower_Half_Square = false;
                          
                              return FindTarghet;
                          
                          }
                          
                          /***********MYQThread .cpp    qthread::run*****************/
                          void datathread::run()   
                          {
                          ...
                          ...
                          ...
                          
                          FindACPTarghet OneTarghet = FindCentPoint(rect_points, true, false);
                                                            centrale =  OneTarghet.Get_centrale;
                                                            mezzo_rect_risc = OneTarghet.Get_mezzo_rect_risc;
                                                            mezzo_rect_risc1 = OneTarghet.Get_mezzo_rect_risc1;
                                                            mezzo_rect_risc_pt2 = OneTarghet.Get_mezzo_rect_risc_pt2;
                                                            mezzo_rect_risc_pt3 = OneTarghet.Get_mezzo_rect_risc_pt3;
                                                            intbarix = OneTarghet.X_Point;
                                                            intbariy = OneTarghet.Y_point;
                                                            bariangle = OneTarghet.Angle;
                          
                          

                          Not understand very well why I can't use return with struct ....

                          Regards
                          Giorgio

                          bkt

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 27 Sept 2016, 16:22 last edited by
                            #14

                            But you can use struct as return. :)

                            FindTarghet.Get_centrale = F_centrale;

                            what is F_central?
                            I dont see you define it ?
                            so that would explain "undefined"

                            G 1 Reply Last reply 27 Sept 2016, 16:38
                            0
                            • M mrjj
                              27 Sept 2016, 16:22

                              But you can use struct as return. :)

                              FindTarghet.Get_centrale = F_centrale;

                              what is F_central?
                              I dont see you define it ?
                              so that would explain "undefined"

                              G Offline
                              G Offline
                              gfxx
                              wrote on 27 Sept 2016, 16:38 last edited by
                              #15

                              @mrjj mmm....

                              
                              /********* as global var in MYQThread .cpp*****************/
                              int F_intbarix = 0, F_intbariy = 0;
                              double F_lung1 = 0, F_lung11 = 0, F_lung2 = 0, F_lung3 = 0, F_lung4 = 0, F_lung5 = 0, F_barix = 0, F_bariy = 0, F_bariangle = 0, F_bariangle_template = 0;
                              int DeF_barix = 0, DeF_bariy = 0, DeF_bariangle = 0, DeF_bariangle_template = 0;
                              int X_mezzo_rect_risc = 0, Y_mezzo_rect_risc = 0, X_mezzo_rect_risc1 = 0, Y_mezzo_rect_risc1 = 0;
                              int X_mezzo_rect_risc_pt2 = 0, Y_mezzo_rect_risc_pt2 = 0, X_mezzo_rect_risc_pt3 = 0, Y_mezzo_rect_risc_pt3 = 0;
                              int DeF_Major_Side1 = 0, DeF_Major_Side2 = 0, DeF_Get_Upper_Half_Square = 0, DeF_Get_Lower_Half_Square = 0;
                              
                              cv::Point F_centrale = cv::Point(0 ,0); <------------------------------------------------------- /****** and use these variable into calculation and as result too... so i put it into return struc as you see****/
                              
                              cv::Point F_mezzo_rect_risc = cv::Point(0 ,0);
                              cv::Point F_mezzo_rect_risc1 = cv::Point(0 ,0);
                              cv::Point F_mezzo_rect_risc_pt2 = cv::Point(0 ,0);
                              

                              Regards
                              giorgio

                              bkt

                              G 1 Reply Last reply 27 Sept 2016, 16:44
                              0
                              • G gfxx
                                27 Sept 2016, 16:38

                                @mrjj mmm....

                                
                                /********* as global var in MYQThread .cpp*****************/
                                int F_intbarix = 0, F_intbariy = 0;
                                double F_lung1 = 0, F_lung11 = 0, F_lung2 = 0, F_lung3 = 0, F_lung4 = 0, F_lung5 = 0, F_barix = 0, F_bariy = 0, F_bariangle = 0, F_bariangle_template = 0;
                                int DeF_barix = 0, DeF_bariy = 0, DeF_bariangle = 0, DeF_bariangle_template = 0;
                                int X_mezzo_rect_risc = 0, Y_mezzo_rect_risc = 0, X_mezzo_rect_risc1 = 0, Y_mezzo_rect_risc1 = 0;
                                int X_mezzo_rect_risc_pt2 = 0, Y_mezzo_rect_risc_pt2 = 0, X_mezzo_rect_risc_pt3 = 0, Y_mezzo_rect_risc_pt3 = 0;
                                int DeF_Major_Side1 = 0, DeF_Major_Side2 = 0, DeF_Get_Upper_Half_Square = 0, DeF_Get_Lower_Half_Square = 0;
                                
                                cv::Point F_centrale = cv::Point(0 ,0); <------------------------------------------------------- /****** and use these variable into calculation and as result too... so i put it into return struc as you see****/
                                
                                cv::Point F_mezzo_rect_risc = cv::Point(0 ,0);
                                cv::Point F_mezzo_rect_risc1 = cv::Point(0 ,0);
                                cv::Point F_mezzo_rect_risc_pt2 = cv::Point(0 ,0);
                                

                                Regards
                                giorgio

                                G Offline
                                G Offline
                                gfxx
                                wrote on 27 Sept 2016, 16:44 last edited by
                                #16

                                @gfxx so I try to define F_centrale into struc func..

                                FindACPTarghet FindCentPoint( cv::Point2f Square_Points[4], bool Find_Upper_Half_Square, bool Find_Lower_Half_Square)
                                {
                                
                                    FindACPTarghet FindTarghet;  <----------------------------------------
                                
                                   int F_intbarix = 0, F_intbariy = 0;
                                    double F_lung1 = 0, F_lung11 = 0, F_lung2 = 0, F_lung3 = 0, F_lung4 = 0, F_lung5 = 0, F_barix = 0, F_bariy = 0, F_bariangle = 0, F_bariangle_template = 0;
                                    int DeF_barix = 0, DeF_bariy = 0, DeF_bariangle = 0, DeF_bariangle_template = 0;
                                    int X_mezzo_rect_risc = 0, Y_mezzo_rect_risc = 0, X_mezzo_rect_risc1 = 0, Y_mezzo_rect_risc1 = 0;
                                    int X_mezzo_rect_risc_pt2 = 0, Y_mezzo_rect_risc_pt2 = 0, X_mezzo_rect_risc_pt3 = 0, Y_mezzo_rect_risc_pt3 = 0;
                                    int DeF_Major_Side1 = 0, DeF_Major_Side2 = 0, DeF_Get_Upper_Half_Square = 0, DeF_Get_Lower_Half_Square = 0;
                                
                                    cv::Point F_centrale = cv::Point(0 ,0);
                                
                                    cv::Point F_mezzo_rect_risc = cv::Point(0 ,0);
                                    cv::Point F_mezzo_rect_risc1 = cv::Point(0 ,0);
                                    cv::Point F_mezzo_rect_risc_pt2 = cv::Point(0 ,0);
                                    cv::Point F_mezzo_rect_risc_pt3 = cv::Point(0 ,0);
                                    cv::Point F_un_quarto_rect_risc = cv::Point(0 ,0);
                                    cv::Point F_un_quarto_rect_risc1 = cv::Point(0 ,0);
                                    cv::Point F_un_quarto_rect_risc_pt2 = cv::Point(0 ,0);
                                    cv::Point F_un_quarto_rect_risc_pt3 = cv::Point(0 ,0);
                                    bool choose0 = false, choose1 = false, choose2 = false, choose3 = false;
                                
                                    F_lung1 = std::pow((std::pow((Square_Points[0].x - Square_Points[1].x),2) + std::pow((Square_Points[0].y - Square_Points[1].y),2)), 0.5);
                                    F_lung2 = std::pow((std::pow((Square_Points[1].x - Square_Points[2].x),2) + std::pow((Square_Points[1].y - Square_Points[2].y),2)), 0.5);
                                
                                    if (F_lung2 > F_lung1)
                                    {..................
                                

                                but result is the same...

                                Regards
                                giorgio

                                bkt

                                G 1 Reply Last reply 27 Sept 2016, 17:34
                                0
                                • G gfxx
                                  27 Sept 2016, 16:44

                                  @gfxx so I try to define F_centrale into struc func..

                                  FindACPTarghet FindCentPoint( cv::Point2f Square_Points[4], bool Find_Upper_Half_Square, bool Find_Lower_Half_Square)
                                  {
                                  
                                      FindACPTarghet FindTarghet;  <----------------------------------------
                                  
                                     int F_intbarix = 0, F_intbariy = 0;
                                      double F_lung1 = 0, F_lung11 = 0, F_lung2 = 0, F_lung3 = 0, F_lung4 = 0, F_lung5 = 0, F_barix = 0, F_bariy = 0, F_bariangle = 0, F_bariangle_template = 0;
                                      int DeF_barix = 0, DeF_bariy = 0, DeF_bariangle = 0, DeF_bariangle_template = 0;
                                      int X_mezzo_rect_risc = 0, Y_mezzo_rect_risc = 0, X_mezzo_rect_risc1 = 0, Y_mezzo_rect_risc1 = 0;
                                      int X_mezzo_rect_risc_pt2 = 0, Y_mezzo_rect_risc_pt2 = 0, X_mezzo_rect_risc_pt3 = 0, Y_mezzo_rect_risc_pt3 = 0;
                                      int DeF_Major_Side1 = 0, DeF_Major_Side2 = 0, DeF_Get_Upper_Half_Square = 0, DeF_Get_Lower_Half_Square = 0;
                                  
                                      cv::Point F_centrale = cv::Point(0 ,0);
                                  
                                      cv::Point F_mezzo_rect_risc = cv::Point(0 ,0);
                                      cv::Point F_mezzo_rect_risc1 = cv::Point(0 ,0);
                                      cv::Point F_mezzo_rect_risc_pt2 = cv::Point(0 ,0);
                                      cv::Point F_mezzo_rect_risc_pt3 = cv::Point(0 ,0);
                                      cv::Point F_un_quarto_rect_risc = cv::Point(0 ,0);
                                      cv::Point F_un_quarto_rect_risc1 = cv::Point(0 ,0);
                                      cv::Point F_un_quarto_rect_risc_pt2 = cv::Point(0 ,0);
                                      cv::Point F_un_quarto_rect_risc_pt3 = cv::Point(0 ,0);
                                      bool choose0 = false, choose1 = false, choose2 = false, choose3 = false;
                                  
                                      F_lung1 = std::pow((std::pow((Square_Points[0].x - Square_Points[1].x),2) + std::pow((Square_Points[0].y - Square_Points[1].y),2)), 0.5);
                                      F_lung2 = std::pow((std::pow((Square_Points[1].x - Square_Points[2].x),2) + std::pow((Square_Points[1].y - Square_Points[2].y),2)), 0.5);
                                  
                                      if (F_lung2 > F_lung1)
                                      {..................
                                  

                                  but result is the same...

                                  Regards
                                  giorgio

                                  G Offline
                                  G Offline
                                  gfxx
                                  wrote on 27 Sept 2016, 17:34 last edited by
                                  #17

                                  @gfxx Ok the function works whithout error ... but I have 0 result value for all variables ....

                                  Regards
                                  giorgio

                                  bkt

                                  G 1 Reply Last reply 28 Sept 2016, 16:34
                                  0
                                  • G gfxx
                                    27 Sept 2016, 17:34

                                    @gfxx Ok the function works whithout error ... but I have 0 result value for all variables ....

                                    Regards
                                    giorgio

                                    G Offline
                                    G Offline
                                    gfxx
                                    wrote on 28 Sept 2016, 16:34 last edited by
                                    #18

                                    @gfxx mmm.... these type of approach is not desirable in my case ... so at the last I solve my problem wit a specific c++ class with function that return struct result ... if someone had this same problem or wish to create a class with a return statement struct or a void with a return struct placed here the basic steps ....

                                    /*************************FILE.h*********************************/
                                    
                                    #ifndef FILE_H
                                    #define FILE_H
                                    
                                    #include <QThread> /**** and other magic include ****/
                                    #include <QtCore/QVariant>
                                    .....
                                    
                                    
                                    struct myFirstStruct{
                                        cv::Point2f Square_Points[4];
                                        bool Up1_2Square;
                                        bool Down1_2Square;
                                        bool returnValue1;
                                        bool returnValue2;
                                        ...... /***other member DECLARE ***/
                                    
                                    };
                                    
                                    
                                    
                                    class File
                                    {
                                    public:
                                        File();
                                    
                                        myFirstStruct myVoid( cv::Point2f Square_Points[4], bool Up1_2Square, bool Down1_2Square);
                                        struct myFirstStruct MyIstance;
                                    
                                    private:
                                    
                                    
                                    };
                                    
                                    #endif // FILE_H
                                    
                                    /*************************FILE.cpp*********************************/
                                    
                                    #include "File.h"
                                    
                                    
                                    
                                    File::File()
                                    {
                                    
                                    }
                                    
                                    
                                      myFirstStruct File::myVoid(cv::Point2f Square_Points[4], bool Up1_2Square, bool Down1_2Square)
                                        {
                                    /***do somethings*****/
                                    
                                    MyIstance.returnValue1 = calculatedvalue1;
                                    MyIstance.returnValue2 = calculatedvalue2;
                                    
                                    return MyIstance;
                                    }
                                    
                                    /*************************InSomeFileOfYourApp.cpp*********************************/
                                    
                                    #include "File.h"
                                    
                                    int var1; .....
                                    
                                    Your::mainOrSub(){
                                    
                                    File MyClassIstance;
                                    
                                    MyClassIstance.myVoid(cv-point-value, bool-value, bool-value);
                                    
                                    yourCalculatedData1 =  myVoid.MyIstance.returnValue1;
                                    yourCalculatedData2 =  myVoid.MyIstance.returnValue2;
                                    
                                    .......
                                    }
                                    
                                    
                                    
                                    

                                    I hope These Help someone ...
                                    Regards
                                    Giorgio

                                    bkt

                                    VRoninV 1 Reply Last reply 28 Sept 2016, 17:07
                                    -1
                                    • G gfxx
                                      28 Sept 2016, 16:34

                                      @gfxx mmm.... these type of approach is not desirable in my case ... so at the last I solve my problem wit a specific c++ class with function that return struct result ... if someone had this same problem or wish to create a class with a return statement struct or a void with a return struct placed here the basic steps ....

                                      /*************************FILE.h*********************************/
                                      
                                      #ifndef FILE_H
                                      #define FILE_H
                                      
                                      #include <QThread> /**** and other magic include ****/
                                      #include <QtCore/QVariant>
                                      .....
                                      
                                      
                                      struct myFirstStruct{
                                          cv::Point2f Square_Points[4];
                                          bool Up1_2Square;
                                          bool Down1_2Square;
                                          bool returnValue1;
                                          bool returnValue2;
                                          ...... /***other member DECLARE ***/
                                      
                                      };
                                      
                                      
                                      
                                      class File
                                      {
                                      public:
                                          File();
                                      
                                          myFirstStruct myVoid( cv::Point2f Square_Points[4], bool Up1_2Square, bool Down1_2Square);
                                          struct myFirstStruct MyIstance;
                                      
                                      private:
                                      
                                      
                                      };
                                      
                                      #endif // FILE_H
                                      
                                      /*************************FILE.cpp*********************************/
                                      
                                      #include "File.h"
                                      
                                      
                                      
                                      File::File()
                                      {
                                      
                                      }
                                      
                                      
                                        myFirstStruct File::myVoid(cv::Point2f Square_Points[4], bool Up1_2Square, bool Down1_2Square)
                                          {
                                      /***do somethings*****/
                                      
                                      MyIstance.returnValue1 = calculatedvalue1;
                                      MyIstance.returnValue2 = calculatedvalue2;
                                      
                                      return MyIstance;
                                      }
                                      
                                      /*************************InSomeFileOfYourApp.cpp*********************************/
                                      
                                      #include "File.h"
                                      
                                      int var1; .....
                                      
                                      Your::mainOrSub(){
                                      
                                      File MyClassIstance;
                                      
                                      MyClassIstance.myVoid(cv-point-value, bool-value, bool-value);
                                      
                                      yourCalculatedData1 =  myVoid.MyIstance.returnValue1;
                                      yourCalculatedData2 =  myVoid.MyIstance.returnValue2;
                                      
                                      .......
                                      }
                                      
                                      
                                      
                                      

                                      I hope These Help someone ...
                                      Regards
                                      Giorgio

                                      VRoninV Offline
                                      VRoninV Offline
                                      VRonin
                                      wrote on 28 Sept 2016, 17:07 last edited by
                                      #19

                                      @gfxx Class and Struct are the same thing.

                                      struct MyClass{
                                      // stuff
                                      };
                                      // is the same as:
                                      class MyClass{
                                      public:
                                      // stuff
                                      };
                                      

                                      see http://www.cplusplus.com/doc/tutorial/classes/ for a quick overview of how to use classes and structs

                                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                      ~Napoleon Bonaparte

                                      On a crusade to banish setIndexWidget() from the holy land of Qt

                                      G 1 Reply Last reply 28 Sept 2016, 20:46
                                      2
                                      • VRoninV VRonin
                                        28 Sept 2016, 17:07

                                        @gfxx Class and Struct are the same thing.

                                        struct MyClass{
                                        // stuff
                                        };
                                        // is the same as:
                                        class MyClass{
                                        public:
                                        // stuff
                                        };
                                        

                                        see http://www.cplusplus.com/doc/tutorial/classes/ for a quick overview of how to use classes and structs

                                        G Offline
                                        G Offline
                                        gfxx
                                        wrote on 28 Sept 2016, 20:46 last edited by
                                        #20

                                        @VRonin yes struct and class is quite similar .... but not the same things..... I know .. some C programmers not like class and prefer struct .... When I was A good programmer I use me too only struct and no class .... but for now I'm happy class exist .... ;)

                                        regards
                                        Giorgio

                                        bkt

                                        VRoninV 1 Reply Last reply 29 Sept 2016, 07:16
                                        0
                                        • G gfxx
                                          28 Sept 2016, 20:46

                                          @VRonin yes struct and class is quite similar .... but not the same things..... I know .. some C programmers not like class and prefer struct .... When I was A good programmer I use me too only struct and no class .... but for now I'm happy class exist .... ;)

                                          regards
                                          Giorgio

                                          VRoninV Offline
                                          VRoninV Offline
                                          VRonin
                                          wrote on 29 Sept 2016, 07:16 last edited by VRonin
                                          #21

                                          @gfxx C has no classes. C has only structs and they cannot contain methods, just members. C is not an object oriented language. In C++ they are the same, the only difference is the default access level (public for struct, private for class)

                                          http://www.geeksforgeeks.org/g-fact-76/

                                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                          ~Napoleon Bonaparte

                                          On a crusade to banish setIndexWidget() from the holy land of Qt

                                          G 1 Reply Last reply 29 Sept 2016, 09:05
                                          2

                                          11/22

                                          27 Sept 2016, 14:29

                                          • Login

                                          • Login or register to search.
                                          11 out of 22
                                          • First post
                                            11/22
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved