how to use non static member function within a class with attach interrupt?

Hey guys!
I hope everybody is well. First and foremost, I must admit that I am a newbie to C++ so any kind of help I will highly appreciate.
My problem is that I am trying to implement a library for the encoder. I am creating a class to calculate the angle of the encoder. The problem is that I use attach interrupt method which requires the ISR to be static function, I need to pass an instance of the object to ISR as the ISR depend mainly on variables of the object. However, I am not able to do so as when I make ISR a member of the class, the attach interrupt calls out an error saying that it can not work with nonstatic member function. here is my CPP file

#include "encoder.h"

//<<constructor and destructor>> setup the encoder
Encoder::Encoder(){}
Encoder::~Encoder(){}


double Encoder::read_angle(double ppr,double gear_ratio)
{
	return abs(encoderPosA*360/(ppr*gear_ratio*4.0));
}

double Encoder::control_angle(double refrence_angle,double angle,double Kp)
{
	error=Kp*(refrence_angle-abs(angle));
	P_term=constrain(error,-255,255);
	P_term=abs(P_term);
	return P_term;
}

double Encoder::control_angle(double refrence_angle,double angle)
{
	Kp=0.5;
	error=refrence_angle-abs(angle);
	P_term=constrain(Kp*error,-255,255);
	P_term=abs(P_term);
	return P_term;
	}

void Encoder::chB_change()
{
	//Serial.println("I am In chB_change");

	// look for a low-to-high on channel B
 if (digitalRead(ChB) == HIGH)
  {
    // check channel A to see which way encoder is turning
    if (digitalRead(ChA) == HIGH)
    {
      encoderPosA++;         // CW
    }
    else
    {
      encoderPosA--;         // CCW
    }
  }
  // Look for a high-to-low on channel B
  else {
    // check channel B to see which way encoder is turning
    if (digitalRead(ChA) == LOW) {
      encoderPosA++;          // CW
    }
    else {
      encoderPosA--;          // CCW
    }
  }
}

void Encoder::chA_change()
{
	//Serial.println("I am In chA_change");
  // look for a low-to-high on channel A
  if (digitalRead(ChA) == HIGH) {
    // check channel B to see which way encoder is turning
    if (digitalRead(ChB) == LOW) {
      encoderPosA++;         // CW
    }
    else {
      encoderPosA--;         // CCW
    }
  }
  else   // must be a high-to-low edge on channel A
  {
    // check channel B to see which way encoder is turning
    if (digitalRead(ChB) == HIGH) {
      encoderPosA++;          // CW
    }
    else {
      encoderPosA--;          // CCW
    }
  }
}

void Encoder::attach(int chA, int chB)
{
	ChA = chA;
	ChB = chB;
	pinMode(chA, INPUT_PULLUP);
	pinMode(chB, INPUT_PULLUP);
	attachInterrupt(digitalPinToInterrupt(chA), (funCall)chA_change,CHANGE);
        attachInterrupt(digitalPinToInterrupt(chB), (funCall)chB_change,CHANGE);
}

Here is my h file to

#ifndef Encoder_H
#define Encoder_H

#include <Arduino.h>
class Encoder{
public:
	Encoder();
	~Encoder();
	double read_angle(double ppr,double gear_ratio);
	// void reset_angle();
	double control_angle(double ref_angle,double angle);
	double control_angle(double ref_angle,double angle, double Kp);
	void attach(int a, int b);
	void chB_change();
	void chA_change();	
	typedef void (* funCall)(); // functions pointer
    double ppr;
    double gear_ratio;
    double angle;
    double refrence_angle;
    volatile long encoderPosA = 0;
    double error=0;
    double Kp=0;
    double P_term=0;
    int ChA;
    int ChB;
	};
#endif

I am not sure how to send an instance of the object while keeping the method static. I have tried using std::bind to send an instance of the object however it keeps outputting an error. The error is " error: ‘bind’ is not a member of ‘std’". When I include functional in the h file, Arduino is not able to find a functional file. I downloaded a library in Arduino called ArduinoSTL which has the functional file, however, I discovered it does not allow std:: bind to work properly.

void Encoder::attach(int chA, int chB)
{
	ChA = chA;
	ChB = chB;
	pinMode(chA, INPUT_PULLUP);
	pinMode(chB, INPUT_PULLUP);
	attachInterrupt(digitalPinToInterrupt(chA), std::bind(&Encoder::chA_change, this),CHANGE);
  attachInterrupt(digitalPinToInterrupt(chB), std::bind(&Encoder::chB_change, this),CHANGE);
}

Please can help is highly appreciated. I really need help

"how to use non static member function within a class with attach interrupt?"

You can't, member functions have a different signature. See: Standard C++

There are alternatives. Look at the code for the PJRC Encoder Library.

I wrote a slightly different one, based on similar techniques: GitHub - gfvalvo/NewEncoder: Rotary Encoder Library.

I really need help

Suppose that you create multiple instances of your Encoder class. An external interrupt happens. Which instance of your class cares?

When you can answer that question, writing the code is trivial.

There are several possible answers. How you write the code depends on YOUR answer.

PaulS:
Suppose that you create multiple instances of your Encoder class. An external interrupt happens. Which instance of your class cares?

When you can answer that question, writing the code is trivial.

There are several possible answers. How you write the code depends on YOUR answer.

My question is how can to pass the static nonmember function an instance of the object. I can use a switch to choose which instance of my class cares. The problem is how to pass the instance itself. if I make the ISR member function to the class, it will no longer be static causing an error with attach an interrupt function

gfvalvo:
"how to use non static member function within a class with attach interrupt?"

You can’t, member functions have a different signature. See: Standard C++

There are alternatives. Look at the code for the PJRC Encoder Library.

I wrote a slightly different one, based on similar techniques: GitHub - gfvalvo/NewEncoder: Rotary Encoder Library.

I have already used other encoder libraries and they are great. However, I am trying to implement the encoder library in a different way. I hoped there was a way to pass an instance of the object to the static isr!!!

I hoped there was a way to pass an instance of the object to the static isr!!!

There is not. The static method of the class needs to know which instances of the class exist, and which one cares AT THIS MOMENT.

You failed to answer all of the questions asked.

mostafahaggag:
I hoped there was a way to pass an instance of the object to the static isr!!!

You can't. That's what I meant when I replied "You can't". You're not the first person to discover this. If it was possible, don't you think the two libraries I linked in my reply would have done it rather than working so hard to come up with different methods?