Click here to Skip to main content
15,890,123 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Need vital help about MFC - ADO.Net (SQL connection) Pin
David Crow4-Oct-11 4:56
David Crow4-Oct-11 4:56 
AnswerRe: Need vital help about MFC - ADO.Net (SQL connection) Pin
symeramon4-Oct-11 5:56
symeramon4-Oct-11 5:56 
AnswerRe: Need vital help about MFC - ADO.Net (SQL connection) Pin
Snorri Kristjansson4-Oct-11 2:24
professionalSnorri Kristjansson4-Oct-11 2:24 
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 
I can't compile the program successfully.
This is the error message:error C2059: syntax error : '*'.(I just show the first error message.)
And here is the code:

This is the first time I post my problem to CodeProject.
Please help me! Thank you in advance!


#include <iostream>
#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';
}
}
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 
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 

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.