Changing parameters of an instance

HI,

I'm new to OOP.

Here's a summary of my code. I want to change the flashing rate of the led but from my reading i cannot find how to do that.

I've read about Delete, Erase, etc...).

class Flasher
{
}

Flasher led1(10, 1000, 300);

void setup()
{
}

void loop()
{
led1.Update()

if (x++ == something)
{
Flasher led1(10, 50, 50);
}

Kind regards,

Your class would need to have methods to update its parameters, don’t call the constructor again or you get a new instance

This would be the brute force way

Flasher instance1(1, 2, 3);
...
instance1.~Flasher(); // destructor
new(&instance1) Flasher(4, 5, 6); // reconstruct
...
// Final destruction is be done automatically

This would be better in my opinion If part of your class intended behavior is to be initialized several times. The constructor of your class can simply use a public configuration method, something like

class Flasher {
public:
  Flasher(int a, int b, int c) {
    configure(a,b,c);
  }
  void configure(int a, int b, int c) { ... }
};

then you can call the method configure yourself what you want to update the settings

Your class/object has no constructor function (Flasher(int a, int b, int c)) so you can't pass it arguments when you create it.

It also doesn't have an ".Update()" method.

If you want a function that will let you change parameters, add it to your class.

Something like:

class Flasher
{
  public:
    Flasher(int param1, int param2, int param3)
    {
      p1 = param1;
      p2 = param2;
      p3 = param3;
    };

    void Update();

    void SetParameters(int param1, int param2, int param3)
    {
      p1 = param1;
      p2 = param2;
      p3 = param3;
    };

  private:
    int p1, p2, p3;
};

void Flasher::Update()
{
  
}

Flasher led1(10, 1000, 300);

void setup()
{
}

void loop()
{
  static int x;
  const int something = 3000;
  
  led1.Update();

  if (x++ == something)
  {
    led1.SetParameters(10, 50, 50);
  }
}

I think OP removed her/his class code to keep the post short and is trying to re-initialize an instance by calling the constructor... may be I got that wrong

Thank you all for the fast replies.
J-M-L Many many tanks .... it's working with the configure addition.

Mario B