本文发表在 rolia.net 枫下论坛enc lib: enc.h/codec.cpp/cod.h/cod.cpp with a define "_ENC_LIB_"
dec lib: dec.h/codec.cpp/cod.h/cod.cpp with a define "_DEC_LIB_"
exe: test.cpp/dec.h/enc.h
VC reports link error with this code: cod::cod()/cod::~cod()/cod::read_file()
already defined. but everything is ok when I delete #ifdef in cod.cpp/cod.h,
why? anyway to resolve it if I really want those #ifdef? real source is
really big so please dont tell me to duplicate functions.
thanks,
///////////////////////////////////////////////////////
//cod.cpp
#include "stdio.h" #include "cod.h"
cod::cod(){} cod::~cod(){} void cod::read_file(){ printf("cod::read_file\n");}
#ifdef _DEC_LIB_ void cod::dec(){ printf("cod::dec\n");} #endif
#ifdef _ENC_LIB_ void cod::enc(){ printf("cod::enc\n");} #endif
//codec.cpp
#include "codec.h" #include "cod.h"
#ifdef _DEC_LIB_ dec::dec(){ pdec = new cod; ((cod *)pdec)->read_file();}
dec::~dec(){ delete pdec;} void dec::decode(){ ((cod *)pdec)->dec();}
#endif
#ifdef _ENC_LIB_ enc::enc(){ penc = new cod; ((cod *)penc)->read_file();}
enc::~enc(){ delete penc;} void enc::encode(){ ((cod *)penc)->enc();}
#endif
//dec.h
#ifndef enc_h #define enc_h
class enc{ public: void *penc; enc(); ~enc(); void encode();}; #endif
//enc.h
#ifndef enc_h #define enc_h
class enc{ public: void *penc; enc(); ~enc(); void encode();}; #endif
//test.cpp
#include "enc.h" #include "dec.h"
#pragma comment(lib, "enc.lib") #pragma comment(lib, "dec.lib")
void main(){ enc e; e.encode(); dec d; d.decode();}更多精彩文章及讨论,请光临枫下论坛 rolia.net
dec lib: dec.h/codec.cpp/cod.h/cod.cpp with a define "_DEC_LIB_"
exe: test.cpp/dec.h/enc.h
VC reports link error with this code: cod::cod()/cod::~cod()/cod::read_file()
already defined. but everything is ok when I delete #ifdef in cod.cpp/cod.h,
why? anyway to resolve it if I really want those #ifdef? real source is
really big so please dont tell me to duplicate functions.
thanks,
///////////////////////////////////////////////////////
//cod.cpp
#include "stdio.h" #include "cod.h"
cod::cod(){} cod::~cod(){} void cod::read_file(){ printf("cod::read_file\n");}
#ifdef _DEC_LIB_ void cod::dec(){ printf("cod::dec\n");} #endif
#ifdef _ENC_LIB_ void cod::enc(){ printf("cod::enc\n");} #endif
//codec.cpp
#include "codec.h" #include "cod.h"
#ifdef _DEC_LIB_ dec::dec(){ pdec = new cod; ((cod *)pdec)->read_file();}
dec::~dec(){ delete pdec;} void dec::decode(){ ((cod *)pdec)->dec();}
#endif
#ifdef _ENC_LIB_ enc::enc(){ penc = new cod; ((cod *)penc)->read_file();}
enc::~enc(){ delete penc;} void enc::encode(){ ((cod *)penc)->enc();}
#endif
//dec.h
#ifndef enc_h #define enc_h
class enc{ public: void *penc; enc(); ~enc(); void encode();}; #endif
//enc.h
#ifndef enc_h #define enc_h
class enc{ public: void *penc; enc(); ~enc(); void encode();}; #endif
//test.cpp
#include "enc.h" #include "dec.h"
#pragma comment(lib, "enc.lib") #pragma comment(lib, "dec.lib")
void main(){ enc e; e.encode(); dec d; d.decode();}更多精彩文章及讨论,请光临枫下论坛 rolia.net