[SOLVED]should hi use brace assign value or only use it on constructor?

Hi.

I've got some template class and I try to pass value to them.

the main derive class is define here:

template <typename ... Args>
class TimeOutNodeArgs : public TimeOutNode {
	TimeOutNodeArgs<Args...>(){};
	~TimeOutNodeArgs() {delete this;}
	friend class TimeOut;
	MicroTuple<Args...> args;
	ParamsPack<Args...> pack;
	void callbackTrigger() { /*if(pack.func)*/ pack.getPack();}; //bool overload todo
};

then, in another class that manage all node class, I create new instance of nodes. the one that gave mer trouble in with this derived class.

In that class, I create pointer of derive class, then assign value with curly brace. that method was working with initialization but do not seem to work with assignment, so it is what is look like if I try to read it... but it still compile. That is the thing I found strange... :

void timeOut(unsigned long _delay, void (*_callback)(Args ... args), Args ... args){
		TimeOutNodeArgs<Args...> *derivedNode =  new TimeOutNodeArgs<Args...> ;
		print<Args...>(args...);   / can get the ... value
		derivedNode->args = { args... };
		Serial.println(derivedNode->args.template get<1>());  //don't print the value...


	};

am I missing something ? should I write a full constructor instead? of set value function...

Regards

Nitrof

Try this:

derivedNode->args = MicroTuple<Args...>(args...);

Ok.

I do not know what of the 2 thing solve my issue, I found a dummy mistake else where in the code but still, by then I move thing to a constructor, without testing between the 2...

so this what my constructor look like now... :

TimeOutNodeArgs<Args...>(Args ... ts, void (*cb)(Args ..._args) ) : args(ts...), pack(ParamsPack<Args...> { args, cb } ){};

P.s.: Thank arduino_new, that was something that should have work too...

Now... follow to the new bug... lol

those class are use into a linked list in a main class timeOut. when a timeout node is triggered, is is deleted and the next became head.

the pointer semantic use the base class, but when a derive class is use, the arduino crash...
the trigger callback append if I mute the part that delete and move next.

I think of 2 posible problem: my destructor are not ok
or the ase pointer do not hold derived pointer in the handler.

in both case, not shure what I should try/do...

here the 2 class and the handler:

class TimeOutNode {
protected:
	TimeOutNode();
	virtual ~TimeOutNode() = default;
	friend class TimeOut;
	void (*callback)();
	unsigned long delay;
	unsigned long timeStamp;
	TIMEOUT undeletable;	
	TimeOutNode *next;
	TimeOut *linkedTO; //bound timeOut instance*/
	virtual void callbackTrigger();
};

template <typename ... Args>
class TimeOutNodeArgs : public TimeOutNode {
	TimeOutNodeArgs<Args...>(Args ... ts, void (*cb)(Args ..._args) ) : args(ts...), pack(ParamsPack<Args...> { args, cb } ){};
	~TimeOutNodeArgs() {delete this;}
	friend class TimeOut;
	MicroTuple<Args...> args;
	ParamsPack<Args...> pack;
	void callbackTrigger() { /*Serial.println("callbackTrigger call");*/ /*if(pack.func)*/ pack.getPack();}; //bool overload todo
};




bool TimeOut::handler(){
	if(!TimeOut::head) return false; // if there is no timer set, do nothing
	unsigned long now = millis();
	if (now - TimeOut::head->timeStamp > TimeOut::head->delay){
		
		TimeOut::head->callbackTrigger();
		TimeOutNode *temp = TimeOut::head;		
		if(TimeOut::head->next)
			TimeOut::head = TimeOut::head->next; //switch to next timer
		else 
			TimeOut::head = NULL;
		delete temp; //delete triggered timer
	}
	else {
		return false;
	}
}


Regards

Nitrof
~TimeOutNodeArgs() {delete this;}

This is what causes your crash. Remove "delete this;".

Yes!!

you were wright. that's working now.

Some little tweek still to do but cumming soon, a timeOut and interval library that take function with any number and type of arguments !!!

Thanks again.

Regards.

Nitrof