'Blending::Blend': non-standard syntax; use '&' to create a pointer to member



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
45
46
47
48
49
50
51
52
53
54
55
56



   class Blending
{
public:
	Blending()
	{
		
	}

	 void Blend(int, void*);
	

	  double alpha, beta;

	  int  key;

	  int minimumvalue;
	 
};




----------------cpp------------------------
	int maximumvalue = 100;
	int minimumvalue;
	
	void Blending:: Blend(int, void*)
	{
		
		
		alpha = (double)minimumvalue/ 100;
		addWeighted(img,alpha,img2, 1.0 - alpha, 0, des);
		imshow("Blendimage", des);
	}


	int main()
	{
			
		
	Blending bl;

	bl.Blend(minimumvalue, 0);

	createTrackbar("Blend", "Blendimage", &minimumvalue,maximumvalue,bl.Blend);
			
        waitKey(0);
	 
       imshow("Blendimage", des),waitKey(0);

			return 0;
	}










Am trying to use the object of the class to class the member function of the class i run into this error.. any help pls
Last edited on
Can we see the definition of createTrackbar? Calling b1.Blend (without parentheses) signifies that you are trying to pass in a pointer-to-member-function to the function -- is this correct? Edit: Nevermind, as Peter87 pointed out, it's just bad syntax. The function pointer must be passed in the static way that he mentioned.

Also, why do you have minimumvalue defined as both a global variable and a class member variable? Really confusing.
Third, what is the point of the void* parameter for your Blend function? Or either parameter, seeing as you don't use either of them.

Are you trying to do alpha compositing (blending)?
Last edited on
In order to get a pointer to a member function you need to specify the class and use the & operator.

 
&Blending::Blend

Apparently you can also use the object syntax &bl.Blend but I think that is a bit misleading because the pointer value doesn't have anything to do with the object.

This will unfortunately not work because pointers to non-static member functions does not have the same type as pointers to regular functions. One way around this is to declare a static callback function and use the void* parameter to receive the this pointer.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Blending
{
public:
	...
	
	void Blend(int);

	static void Blend_callback(int value, void* objPtr)
	{
		static_cast<Blending*>(objPtr)->Blend(value);
	}
	
	...
};

...

createTrackbar("Blend", "Blendimage", &minimumvalue, maximumvalue, &Blending::Blend_callback, &bl);
Last edited on
So, you completely ignored the answers people gave you in your previous thread:

http://www.cplusplus.com/forum/general/248947/

Why?
So, you completely ignored the answers people gave you in your previous thread:

http://www.cplusplus.com/forum/general/248947/

Why?
i have tried that, but the createtrackbar accept just the function name not the other way round
I also posted a link to FAQ explaining how to do pointers to member functions.

So, instead of engaging with the people who were giving you help, to try and clarify things, you chose to just completely ignore them, and act as if no-one had tried to help you.

That's rather a rude way to behave towards those taking the time and effort to help you.
Last edited on
Am sorry that isn't the case, i actually tried your link but couldn't get any solution to the problem, thanks though ...
Topic archived. No new replies allowed.