类作为函数 c++ 的参数
我编写了一堆加密算法作为类,现在我想实现加密模式(维基百科中显示的通用模式,而不是算法规范中的特定模式)。我如何编写一个可以接受任何类的函数?
编辑:
这就是我想要完成的任务
class mode{
private:
algorithm_class
public:
mode(Algorithm_class, key, mode){
algorithm_class = Algorithm_class(key, mode);
}
};
I wrote a bunch of crypto algorithms as classes and now I want to implement encryption modes (generalized modes shown in wikipedia, not the specific ones in the algorithms' specifications). How would I write a function that can accept any of the classes?
edit:
here's what i want to accomplish
class mode{
private:
algorithm_class
public:
mode(Algorithm_class, key, mode){
algorithm_class = Algorithm_class(key, mode);
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用抽象类:
这样,当您调用
_algo->Encrypt
时 - 您不知道也不关心您正在使用哪种特定算法,只是它实现了接口所有的加密算法都应该被实现。You can use abstract classes:
In this way when you call
_algo->Encrypt
- you don't know and don't care about which specific algorithm you're using, just that it implements the interface all the crypto algorithms should be implementing.嗯,怎么样
?
不需要
mode
和key
参数,因为算法可以由用户创建:Well, how about
?
No need for
mode
andkey
parameters, as the algorithm can be created by the user: