I am trying to understand delegation in c++. I read that "delegation is pointer to function", and i saw several examples, but unfortunately I cant get it. I have created code to try, because I thought that maybe while programming i will understand it. Unfortunately I didn't.
#include <iostream>
using namespace std;
class person{
private:
int age;
public:
person(age){
this->age = age;
}
// virtual void changeAge(int arg) = 0;
};
class addNumber {
public:
int changeAge(int arg) {
arg += arg+1;
}
};
int main(){
person Olaf;
}
So based on this source I tried:
Olaf = &addNumber::changeAge(10);
or
addNumber test;
Olaf = &addNumber::changeAge(10);
Both does not work. That means program is not compiling.
I want to make person object to use changeName
of addNumber
class method to change the age of instance person class.