Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: teensy4.0 linux18.04 compilation calss vector init

  1. #1

    teensy4.0 linux18.04 compilation calss vector init

    Hi
    sort presentation :

    Code:
    class a_classe {
    std::vector<double>  m_A
    }
    and try to this in loop:

    Code:
    ...
    a_classe the_class
    ...
    the_class.m_A= {1,2};
    Compile but seemnot afect values to vector m_A

    Another way :

    Code:
    class a_classe {
    std::vector<double>  m_A
    
    void afunction(){
    the_class.m_A= {1,2};
    }
    
    }
    works fine but not convenient because definition is hard coded the class can only have an only one instantiation/definition.

    How can do to do it out of class definition?
    Thank's Laurent.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,980
    Please show complete programs. Even if the rest of the code is trivial, it is much easier to answer if we can copy the code into Arduino and run on a Teensy without the work of adding (guessing) the missing lines.

  3. #3
    I put this code sample for fun...

    Because when I test it to verify that my post sample doesn't works it is work fine...
    The only difference is is that I putit in a .h .cpp files...
    So I do compare with the original code.
    Sorry for these troubles...

    Code:
    #include <vector>
    
    
    
    class Un_rst
    
    {
        public:
        std::vector<double>  m_A;
        double compute();  
        
     
    };
    
    double Un_rst::compute()
    {
      Serial.println();
        for (unsigned i = 0; i <= m_A.size() - 1; i++) {Serial.print("m_A: "); Serial.print(m_A[i],5);} ;
      Serial.println();
    };
    
    
    
    
    Un_rst theRst;
    
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(115200);//USB
       while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }
      //
      
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      theRst.m_A={1,2,3};
      theRst.compute();
    }
    Last edited by LaurentDelaon; 03-03-2021 at 11:17 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •