#include<iostream>
#include<cstdio>
#include<new>
#include<string>
using namespace std;
class Synteza
{
public:
string f1(double x,string n){return "jestem f1";}
string f2(double x,string n){return "jestem f2";}
string f3(double x,string n){return "jestem f3";}
string(Synteza::*wsk)(double,string);
string funkcja(int x)
{
string f="";
double iks=0.46;
switch(x)
{
case 1:
{this->wsk=&Synteza::f1;
break;}
case 2:
{this->wsk=&Synteza::f2;
break;}
case 3:
{this->wsk=&Synteza::f3;
break;}
}
return (this->*wsk)(iks,f);
}
};
int main()
{
string jakis="ifdjfid";
double iks=0.89;
Synteza obiekt;
obiekt.wsk=&Synteza::f1;
cout << (obiekt.*wsk)(iks,jakis) << endl;
cout << obiekt.funkcja(2) << endl;
getchar();
return 0;}
Ćwiczę sobie wskaźniki na funkcje.
Napisałem prosty programik. Sposób z wywołaniem przez odrębną metodę działa, jednak kompilator protestuje przy wywołaniu w pierwszym coucie.
W czym może tkwić problem?