H
Hunter Hou
Hello,
I have some code to implement combination of composite and command patterns.
Here is the problem:
======
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 ){}
void execute( int& num ) {
(receiver->*action) ( num );
}
};
......
int main() {
Number object;
Command* commands[ 3 ];
commands[ 0 ] = &SimpleCommand( &object, &Number::dubble ); <<<<<<<<<<<
........
}
When I compiled this program, <<<< line always said
"warning: taking address of temporary"
I didn't figure out why there's a temporary address.
Any help will be appreciated.
Thanks
hunter
I have some code to implement combination of composite and command patterns.
Here is the problem:
======
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 ){}
void execute( int& num ) {
(receiver->*action) ( num );
}
};
......
int main() {
Number object;
Command* commands[ 3 ];
commands[ 0 ] = &SimpleCommand( &object, &Number::dubble ); <<<<<<<<<<<
........
}
When I compiled this program, <<<< line always said
"warning: taking address of temporary"
I didn't figure out why there's a temporary address.
Any help will be appreciated.
Thanks
hunter