I am trying to create a vector of objects that can have pointers to functions. I would appreciate some help with this as I don't really know what to do
#include <stdlib.h>
#include <windows.h>
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Card
{ public:
typedef void (*FunctType)(vector<Card> &KaibaHand, vector<Card> &KaibaDeck, vector<Card> &, vector< vector<Card> > &, vector<Card> &KaibaGraveyard, vector<Card> &YugiGraveyard, int &, int &);
FunctType GetEffect() {return *Effect;}
void SetEffect(FunctType* setEffect) {Effect = setEffect; }
string GetName() {return Name;}
void SetName(const string& setName) {Name = setName; }
private:
FunctType* Effect;
string Name;
};
typedef void (*FunctType)(
vector<Card> &,
vector<Card> &,
vector< vector<Card> > &,
vector<Card> &,
vector<Card> &);
vector<Card> KaibaDeck(40);
vector< vector<Card> > Field(4, vector<Card>(5));
vector<Card> KaibaHand;
//void KMP( FunctType* fn )
void KMP(vector<Card> &KaibaDeck)
{
vector<Card> v1;
vector<vector<Card> > v2;
int num;
cout<<"enter a number"<<endl;
cin>>num;
KaibaHand.push_back(KaibaDeck[num]);
Field[0][0]=KaibaHand[0];
Field[0][0].GetEffect();// problem here
}
void HEAVYSTORM(vector<Card> &,
vector<Card> &,
vector< vector<Card> > &,
vector<Card> &,
vector<Card> &)
{
cout<<"This card destroys ALL magic and traps cards on the field!!"<<endl;
for (int i=0; i<5; i++)
{
Field[3][i]=Card();
}
}
void POTOFGREED(vector<Card> &,
vector<Card> &,
vector< vector<Card> > &,
vector<Card> &,
vector<Card> &)
{cout<<" pot of greed"<<endl;}
int main()
{
// FunctType vector<Card> KaibaDeck(2);
vector<Card> KaibaDeck(2); //I have no idea what to do here. I just want a Card() vector that can store functions OR have the SetEffect member function be able to take in the HEAVYSTORM and POTOFGREED functions
//KaibaDeck[0] = HEAVYSTORM;
//KaibaDeck[1] = POTOFGREED;
KaibaDeck[0].SetEffect(HEAVYSTORM);
KaibaDeck[1].SetEffect(POTOFGREED);
KMP(KaibaDeck);
return 0;
}