Is there a way to alias functions in a library?

I have this library (shortened for brevity):

#ifndef BN_h
#define BN_h
#pragma once
#include "Arduino.h"

class BN {
    // bool BlockNot::resetTimer;

public:
    BN(int a = 1, int b = 2);

    bool hasPassed(int c = 0);

private:
	
	int aNumber;

};
#endif
#include <Arduino.h>
#include <BN.h>

BN::BN(int a, int b)
{
	//Various code
}

bool BN::hasPassed(int c) {
	return aNumber == c;
}

I would like to be able to call the hasPassed function using different names (for code readability). I went through different articles on function pointers but I can't seem to get any of the examples to work inside a library.

Does anyone know how to properly create function pointers inside a library?

Mike

This is a good article on pointers to member functions: Standard C++
They are indeed different than pointers to regular functions.

inline bool BN::differentName(int c) {
	hasPassed(int c);
}

?

PS Please don't make a library with a short an ambiguous name like BN...

I would like to be able to call the hasPassed function using different names (for code readability).

The simplest way would be to put the required functions with their different names into the library and have them call the common hasPassed() function

As a matter of interest what sort of names did you have in mind for the functions ?

Delta_G:
All it's doing is a text based find and replace, so be careful how you use this stuff. But as long as you're just substituting one name for another it should work.

How does that translate to #define(ing) a function that has arguments that need to get passed into it and then make decisions based on those arguments? Are you saying something like this should work in my libraries .cpp file?

#include <Arduino.h>
#include <BN.h>

#define isDone BN::hasPassed

BN::BN(int a, int b)
{
 //Various code
}

bool BN::hasPassed(int c) {
 aNumber = c;
}

so that once the library is instantiated, I can just use the name given in the #define statement, like this?

BN bn(10,20);

void someFunction() {
    if (bn.isDone(5)) doSomething; else doSomethingElse;
}

? ? ? ? ?

I suspect that it's advisable that hasPassed actually returns a bool :wink:

sterretje:
I suspect that it's advisable that hasPassed actually returns a bool :wink:

Of course it does...

Guy, why are we messing with macro's here...

What is wrong with my suggested solution in post #3 ?

@UKHeliBob, indeed! Same as I suggested in reply #2 (but with less words..)

Delta_G:

bool BN::hasPassed(int c) {

aNumber = c;
}




Where?

My bad, i fixed it.