teensy4.0 linux18.04 compilation calss vector init

Status
Not open for further replies.
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.
 
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.
 
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:
Status
Not open for further replies.
Back
Top