本文介绍了类作为函数c ++的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一堆加密算法作为类,现在我想实现加密模式(广义模式显示在维基百科,而不是具体的算法的规格)。我如何写一个可以接受任何类的函数?
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?
编辑:
完成
class mode{
private:
algorithm_class
public:
mode(Algorithm_class, key, mode){
algorithm_class = Algorithm_class(key, mode);
}
};
推荐答案
b
template<class AlgorithmType>
class mode{
private:
AlgorithmType _algo;
public:
mode(const AlgorithmType& algo)
: _algo(algo) {}
};
?
不需要 mode
和键
参数,因为算法可以由用户创建:
No need for mode
and key
parameters, as the algorithm can be created by the user:
mode<YourAlgorithm> m(YourAlgorithm(some_key,some_mode));
这篇关于类作为函数c ++的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!