[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] array af funktioner, initialisering og kald af dem.



Hej


Et lille sidespørgsmål. Pointere til "løse" funktioner er tilynelaende let, men jeg har et problem med pointere til funktioner i classes.


Hvorfor er det lige at det i ndenstaaende eksempel virker fint med decode1/mydecoder1 , men ikke virker med decode2/mydecoder2 ?

Eksempel:

void decode1(char* buf, int len) {
....
}

Class CMyDecoder {
public:
	CMyDecoder() {
		mydecoder1 = decode1;
		mydecoder2 = decode2
	};
	~CMyDecoder() {
	};
	void decode2(char *buf, int len);

	void (*mydecoder1)(char* buf, int len);
	void CMyDecoder (*mydecoder2)(char* buf, int len);
};



Peter Maersk-Moller wrote:
Hej

jeg har et lille problem med korrekte erklæringer i C++ for et array af
funktioner.

Følgende er ikke helt korrekt, men med lidt fantasi kan man forestille
sig, hvad jeg mener.

Jeg har tre funktioner som følger

  int adecode(char *p, char *t);
  int vdecode(char *p, char *t);
  int tdecode(char *p, char *t);

Dernaest har jeg funktionenerne

  void setup(int index, int (*decode)(char *p, char *t)) {
    my_array[index] = decode;
  }

  int decode_demuxer(int index, char *p, char *t) {
    return my_array[index](p, t);
  }

Saa vil jeg gerne kunne kalde setup som f.eks.

   setup(512,vdecode);
   setup(513,adecode);

og dernaest vil jeg gerne kunne kalde

  decode_demuxer(512, p, t);

Mine spørgsmål er så

a) Hvordan skal setup erklæres korrekt ?
b) hvordan skal my_array erklæres korrekt ?
c) hvordan lægges funktionerne korrekt ind i my_array ?
d) hvordan kaldes de korrekt i decode_demuxer ?

Med venlig hilsen

Peter



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2007-03-01, 02:01 CET [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] *