错误,因为函数是类中的纯虚拟? [英] Error because function is pure virtual within class?

查看:188
本文介绍了错误,因为函数是类中的纯虚拟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类作为函数c ++ 的参数复制到我的代码,我得到的错误:注意:因为以下虚拟函数是纯在'TEA':和XTEA,但只有这两个函数。其他功能,AES,BLOWFISH,CAMELLIA,RC4,RC5,RC6等都工作。它只是那两个函数是错误的。我不知道为什么。



来自链接的代码(略有修改):

  class CryptoAlgorithm 
{
public:
virtual std :: string encrypt(std :: string DATA)= 0;
virtual std :: string decrypt(std :: string DATA)= 0;
virtual void setkey(std :: string KEY)= 0;
};

和TEA setkey()

  void setkey(std :: string KEY,
unsigned int ROUNDS = 64,
uint32_t DELTA = 0x9e3779b9,uint32_t TOTAL = 0xc6ef3720)

其他类中的所有函数都是相同的。加密/解密只有 std :: string DATA 作为它们的参数。 void setkey std :: string KEY 和其他可选参数。但是,像 setkey 也有其他可选参数的RC6的函数不会报错。



任何原因? / p>

此外,所有类在它们的声明旁边都有:public CryptoAlgorithm

解决方案

您不能创建抽象类的对象。您需要在派生类中修改纯虚函数,以便能够创建派生类的对象。


After copying over the code from Classes as parameter of function c++ into my code, I am getting the error: note: because the following virtual functions are pure within 'TEA': and XTEA, but only those two functions. The other functions, AES, BLOWFISH, CAMELLIA, RC4, RC5, RC6, etc. are all working. Its just those two functions that are erroring. I don't get why.

code from link (slightly modified):

class CryptoAlgorithm
{
   public:
      virtual std::string encrypt(std::string DATA) = 0;
      virtual std::string decrypt(std::string DATA) = 0;
      virtual void setkey(std::string KEY) = 0;
};

and TEA setkey()

void setkey(std::string KEY, 
            unsigned int ROUNDS = 64, 
            uint32_t DELTA = 0x9e3779b9, uint32_t TOTAL = 0xc6ef3720)

All of the functions in the other classes are the same. encrypt/decrypt only have std::string DATA as their arguments. void setkey has std::string KEY and other optional arguments. However, functions like RC6, whose setkey also has other optional arguments does not error.

Any reason why?

Also, all of the classes have : public CryptoAlgorithm next to their declarations.

解决方案

You cannot create objects of abstract classes. You need to ovverride the pure virtual functions in your derived class to be able to create objects of derived class.

这篇关于错误,因为函数是类中的纯虚拟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆