error: no matching function for call to 'Key::Key(Shift (*)())'

Can you see why this does not compile?

Class CS and class Key are both children of class Action.
Class Key constructor takes an Action* parameter.
Key instantiation on line 34 compiles.
Key instantiation on line 37 does not compile; why is that?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>

class Action
{
	public:
		virtual void press()=0;
};

class Shift: public Action
{
	public:
		void press() { std::cout << " press "; }
};

class SC: public Action
{
	private:
		const char scancode;
	public:
		SC(const char sc): scancode(sc) { }
		void press() { std::cout << scancode; }
};

class Key
{
	private:
		Action* const ptrAction;
	public:
		Key(Action* const a): ptrAction(a) { }
		void press() { ptrAction->press(); }
};

SC sc_1('1');
Key key_1(&sc_1);	//this line compiles

Shift shift();
Key key_shift(&shift);	//error: no matching function for call to 'Key::Key(Shift (*)())'
			// Key key_shift(&shift);
			//                     ^
int main()
{
	key_1.press();	
	//key_shift.press();
}

C:\demo_MinGW>g++ aggregation.cpp
aggregation.cpp:37:21: error: no matching function for call to 'Key::Key(Shift (
*)())'
 Key key_shift(&shift);
                     ^
aggregation.cpp:37:21: note: candidates are:
aggregation.cpp:29:3: note: Key::Key(Action*)
   Key(Action* const a): ptrAction(a) { }
   ^
aggregation.cpp:29:3: note:   no known conversion for argument 1 from 'Shift (*)
()' to 'Action*'
aggregation.cpp:24:7: note: Key::Key(const Key&)
 class Key
       ^
aggregation.cpp:24:7: note:   no known conversion for argument 1 from 'Shift (*)
()' to 'const Key&'

Thank you.
In this context, shift is a function that takes no parameters and returns a Shift object.
Remove the parenthesis after it (from Shift shift(); to Shift shift;).
Thank you EssGeEich.
That fixed it; now it runs!
Topic archived. No new replies allowed.