[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.



Nu siger du C++, så vil jeg foreslå at du bruger arv og polymorfi i
stedet for funktions pointere:

//decoder.hpp
class Decoder {
    virtual int decode(char * p, char * t);
};


void add_decoder(int id, Decoder * decoder);
void decode_demuxer(int id, char * p, char * t);

//decoder.cpp
#include <map>
#include "decoder.hpp"

using std::map;

typedef DecoderMap map<int,Decoder*>;

static DecoderMap s_decoders;

void add_decoder(int id, Decoder * decoder) {
    s_decoders[id] = decoder;
}

int decode_demuxer(int id, char * p, char * t) {
    int result = -1;
    DecoderMap::iterator ite = s_decoders.find(id);
    if (ite != s_decoders.end()) {
        result = ite->second->decode(p, t);
    }
    return result;
}


....noget i den stil.


 
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] *