Mam taki oto kod:
#include <iostream>
using namespace std;
class node
{
protected:
struct Data{string name; string surname; int id;} data;
public:
struct Data info()
{
cout<<"Name: \n";
cin>>data.name;
cout<<"Surname: \n";
cin>>data.surname;
cout<<"Id: \n";
cin>>data.id;
return data;
};
void displayInfo()
{
cout<<"Name: "<<data.name<<endl;
cout<<"Surname: "<<data.surname<<endl;
}
int number;
node *next;
};
bool isEmpty(node *head);
char menu();
void insertAsFirstElement(node *&head, node *&last, int number);
void insertl(node *&head, node *&last, int number);
void removel(node *&head, node *&last);
void showList(node *current);
bool isEmpty(node *head)
{
if(head==NULL)
return true;
else
return false;
}
char menu()
{
char choice;
cout<<"Menu\n";
cout<<"1.Add an item\n";
cout<<"2.Remove an item\n";
cout<<"3.Show the list\n";
cout<<"4.Exit\n";
cin>>choice;
return choice;
}
void insertAsFirstElement(node *&head, node *&last, int number)
{
node *temp=new node;
temp->number=number;
temp->next=NULL;
head=temp;
last=temp;
}
void insertl(node *&head, node *&last, int number)
{
if(isEmpty(head))
insertAsFirstElement(head, last, number);
else
{
node *temp=new node;
temp->number=number;
temp->next=NULL;
last->next=temp;
last=temp;
}
}
void removel(node *&head, node *&last)
{
if(isEmpty(head))
cout<<"The list is already empty\n";
else if(head==last)
{
delete head;
head=NULL;
last=NULL;
}
else
{
node *temp=head;
head=head->next;
delete temp;
}
}
void showList(node *current)
{
if(isEmpty(current))
cout<<"The list is empty\n";
else
{
cout<<"The list contains: \n";
while(current!=NULL)
{
cout<<current->number<<endl;
current=current->next;
}
}
}
int main()
{
node *head=NULL;
node *last=NULL;
char choice;
int number;
do
{
choice=menu();
switch(choice)
{
case '1':
{
cout<<"Enter the number\n";
cin>>number;
insertl(head,last,number);
break;
}
case '2':
{
removel(head,last);
break;
}
case '3':
{
showList(head);
break;
}
default: cout<<"System exit\n";
}
}
while(choice!='4');
return 0;
}
I chcialbym stworzyc wskaznik na funkcje info() i displayInfo(), tak aby do funkcji listy np insertAsFirstElement, insertl i showList zamiast parametru number przeslac wskaznik na wyzej wymienione funkcje operujace na structie(aby mozna bylo tworzyc i wyswietlac dane o danym wezle) i nie wiem za bardzo jak sie za to zabrac, probowalem czegos takiego: struct data(node::*fptr)(struct data)=&node::info(); ale zdaje sobie sprawy, ze nie moge korzystac z tych metod gdyz sa niestatyczne(wiec ich adres tworzy sie dopiero wraz ze stworzeniem danego obiektu), czy cos takiego w ogóle mozna zrobic?