Click here to Skip to main content
15,887,596 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Need vital help about MFC - ADO.Net (SQL connection) Pin
symeramon4-Oct-11 4:04
symeramon4-Oct-11 4:04 
QuestionColoring ClistBox control Pin
Benjamin Bruno3-Oct-11 6:40
Benjamin Bruno3-Oct-11 6:40 
QuestionRe: Coloring ClistBox control Pin
David Crow3-Oct-11 6:54
David Crow3-Oct-11 6:54 
GeneralRe: Coloring ClistBox control Pin
Albert Holguin3-Oct-11 7:24
professionalAlbert Holguin3-Oct-11 7:24 
QuestionC++ Class Function Pointer Problem Pin
Falconapollo3-Oct-11 5:37
Falconapollo3-Oct-11 5:37 
QuestionRe: C++ Class Function Pointer Problem Pin
David Crow3-Oct-11 6:38
David Crow3-Oct-11 6:38 
AnswerRe: C++ Class Function Pointer Problem Pin
Richard MacCutchan3-Oct-11 7:00
mveRichard MacCutchan3-Oct-11 7:00 
AnswerRe: found error in line 33: (receiver-> *action)(num); Pin
Software_Developer3-Oct-11 7:20
Software_Developer3-Oct-11 7:20 
It compiled fine after i commented this line out:

C#
/*virtual*/void execute(int &num)
{
//  (receiver-> *action)(num);  //<-----
}



C#
#include < iostream.h >
#include < vector >
using namespace std;
 
class Number
{
	public:
	void dubble(int &value)
	{
	value *= 2;
	}
};
 
class Command
	{
	public:
	virtual void execute(int &) = 0;
};
 
class SimpleCommand: public Command
{
	typedef void(Number:: *Action)(int &);
	Number *receiver;
	Action action;
	public:
	SimpleCommand(Number *rec, Action act)
	{
		receiver = rec;
		action = act;
	}
	/*virtual*/void execute(int &num)
	{
	//	(receiver-> *action)(num);
	}
};
 
class MacroCommand: public Command
{
	vector < Command * > list;
	public:
	void add(Command *cmd)
	{
		list.push_back(cmd);
	}
	/*virtual*/void execute(int &num)
	{
		for (int i = 0; i < list.size(); i++)
		list[i]->execute(num);
	}
};
 
int main()
{
	Number object;
	Command *commands[3];
	commands[0] = &SimpleCommand(&object, &Number::dubble);
 
	MacroCommand two;
	two.add(commands[0]);
	two.add(commands[0]);
	commands[1] = &two;
 
	MacroCommand four;
	four.add(&two);
	four.add(&two);
	commands[2] = &four;
 
	int num, index;
	while (true)
	{
		cout << "Enter number selection (0=2x 1=4x 2=16x): ";
		cin >> num >> index;
		commands[index]->execute(num);
		cout << " " << num << '\n';
	}

	return 0;
}

AnswerRe: C++ Class Function Pointer Problem Pin
TheGreatAndPowerfulOz3-Oct-11 8:03
TheGreatAndPowerfulOz3-Oct-11 8:03 
GeneralRe: C++ Class Function Pointer Problem Pin
Falconapollo3-Oct-11 18:22
Falconapollo3-Oct-11 18:22 
QuestionRookie Alert! Need Help Learning C Pin
Veeshal Beotra2-Oct-11 19:49
Veeshal Beotra2-Oct-11 19:49 
AnswerRe: Rookie Alert! Need Help Learning C Pin
Madhu Nair2-Oct-11 20:30
Madhu Nair2-Oct-11 20:30 
AnswerRe: Rookie Alert! Need Help Learning C Pin
MSTzhao2-Oct-11 21:34
MSTzhao2-Oct-11 21:34 
AnswerRe: Rookie Alert! Need Help Learning C Pin
Richard MacCutchan2-Oct-11 21:42
mveRichard MacCutchan2-Oct-11 21:42 
AnswerRe: Rookie Alert! Need Help Learning C Pin
ThatsAlok2-Oct-11 23:42
ThatsAlok2-Oct-11 23:42 
AnswerRe: Rookie Alert! Need Help Learning C Pin
TheGreatAndPowerfulOz3-Oct-11 7:22
TheGreatAndPowerfulOz3-Oct-11 7:22 
GeneralRe: Rookie Alert! Need Help Learning C Pin
Veeshal Beotra4-Oct-11 6:35
Veeshal Beotra4-Oct-11 6:35 
AnswerRe: Rookie Alert! Need Help Learning C Pin
Legor4-Oct-11 1:43
Legor4-Oct-11 1:43 
GeneralRe: Rookie Alert! Need Help Learning C Pin
Veeshal Beotra4-Oct-11 6:37
Veeshal Beotra4-Oct-11 6:37 
QuestionDrawing text issue Pin
csrss2-Oct-11 9:44
csrss2-Oct-11 9:44 
AnswerRe: Drawing text issue Pin
KingsGambit2-Oct-11 18:30
KingsGambit2-Oct-11 18:30 
GeneralRe: Drawing text issue Pin
csrss3-Oct-11 5:56
csrss3-Oct-11 5:56 
AnswerRe: Drawing text issue Pin
john56322-Oct-11 19:51
john56322-Oct-11 19:51 
GeneralRe: Drawing text issue Pin
csrss3-Oct-11 6:58
csrss3-Oct-11 6:58 
QuestionShow information in the same dialog after press diferent button Pin
antonio3432-Oct-11 6:23
antonio3432-Oct-11 6:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.