i am trying to understand the concepts of c++ as i am not very advanced in it. Although i have a descent knowledge , i have absolutely no idea about whats going on here!!!
I am making a program in which I simply have a template_class with a pointer to function which returns the value of function add. I am using Visual c++ and for some reason it returns the following error in main.cpp :-
Error C3867 'Template_class::add': non-standard syntax; use '&' to create a pointer to member`
main.cpp
#include<iostream>
#include<string>
#include"Template_class.h"
using namespace std;
int main()
{
Template_class <int> t;
t.retrunOperation(4, 5, t.add);
cin.get();
}
Template_class.h
#include<iostream>
template<class T>
class Template_class
{
public:
Template_class()
{
}
~Template_class()
{
}
T add(T var1 , T var2)
{
return var1 + var2;
}
void retrunOperation(T var1 , T var2 , T (*function)(T , T))
{
std::cout << (*function)(var1, var2);
}
};
This may be a invalid question(about which i have no idea) , but as i said i am not an advanced programmer , so please suggest me some solutions