gpt4 book ai didi

c++ - 对 'vtable for 的 undefined reference

转载 作者:太空狗 更新时间:2023-10-29 21:41:04 24 4
gpt4 key购买 nike

我认为重要的是要注意,这在 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; }


};

最佳答案

您似乎对 RSA_433::RSA_433() 有两个定义。一个在.h文件中,一个在.cpp文件中

此外,CipherInterface 类中定义的所有方法都是内联的。根据GCC standard ,

The ISO C++ Standard specifies that all virtual methods of a class that are not pure-virtual must be defined, but does not require any diagnostic for violations of this rule [class.virtual]/8. Based on this assumption, GCC will only emit the implicitly defined constructors, the assignment operator, the destructor and the virtual table of a class in the translation unit that defines its first such non-inline method

这意味着 GCC 将只在翻译单元的目标文件中包含 vftable,其中存在第一个非纯、非内联虚拟成员函数的定义。如果没有这样的定义,vftable 将不会包含在该类中。

关于c++ - 对 'vtable for 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29830013/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com