[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Pointere til funktioner i klassen (C++)



donald_j_axel <sslug@sslug> skrev:

> On Sun, 25 Jul 2004 22:06:47 +0200
> Anders wrote:
>
>> (CVideoFilter::* calc_SAD)
>
> Jeg kan ikke gennemskue din kode, men mangler der ikke en parentes
> her, [...]

Det er mig uklart, hvor du ville sætte parentesen; men nej, den
mangler ikke.

Her er et komplet eksempel, hvis det så bliver lettere at gennemskue.
Så er der i hvert fald noget at lege med.

                    -------------------

#include <iostream>

class C {
public:
	template<int V> int f() { return V; }
	int g() { return 7; }

	int (C::* ptr)();    // Her svarer "ptr" til "calc_SAD"

	C(int (C::* p)()) : ptr(p)
	  { std::cout << (this->*ptr)() << std::endl; }
};

int main()
{
	C o1(&C::f<2>);
	C o2(&C::f<3>);
	C o3(&C::g);
}

                    -------------------


> [...] er asterisk eller pointer-operatoren ikke stærkest bundet til
> det, der står til højre ...

Igen er det mig uklart, hvad du mener. Muligvis er du ikke opmærksom
på, at der var tale om X::*, ikke bare *. Altså en peger til en C++
memberfunktion, ikke en C funktionspeger. Der er stor forskel.


Anders.


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *