我认为需要注意的是,这段代码在Visual Studio 2012上可以编译通过,但在g++上无法通过。在实现RSA.cpp之前,它甚至能够完美编译通过。自那以后我没有修改头文件。错误信息如下:
cipher.o: In function `RSA_433::RSA_433()':
/home/andrew/Desktop/ciphers/RSA.h:18 undefined reference to `vtable for RSA_433'
collect2: error: ld returned 1 exit status
以下是RSA.h文件:
class RSA_433: public CipherInterface
{
public:
RSA_433(){}
virtual bool setKey(const unsigned char* key);
virtual unsigned char* encrypt(const unsigned char* plaintext);
virtual unsigned char* decrypt(const unsigned char* ciphertext);
protected:
RSA* RSAkey;
const char* keyFileName;
};
以及RSA.cpp:
//RSA_433::RSA_433(){} removed
bool RSA_433::setKey(const unsigned char* key){//body}
unsigned char* RSA_433::encrypt(const unsigned char* plaintext){//body}
unsigned char* RSA_433::decrypt(const unsigned char* ciphertext){//body}
RSA.h还继承了以下内容:
class CipherInterface
{
public:
CipherInterface(){}
virtual bool setKey(const unsigned char* key){ return false; }
virtual unsigned char* encrypt(const unsigned char* plaintext){ return NULL; }
virtual unsigned char* decrypt(const unsigned char* ciphertext) { return NULL; }
};
CipherInterface
吗?没有漏掉析构函数吧?(可能未定义,纯虚?) - Luchian Grigore