我必须在c++中的类定义中包含非标准库吗?
Do I have to include non standard libraries to class definitions in C++?
我是c++编程的初学者,也是一般编程的初学者。我已经成功地写了一个代码来计算RSA算法的输出C,当m是十进制时相当于输出一个线性反馈移位寄存器。我把代码放在一个类中,这样我就可以多次使用它。在编译时,我得到错误通知,如:"' keyReg '没有命名类型keyReg.push_back (inpSeq[0]);"当这段代码在主类中时,它在编译时不会产生这样的错误。下面是完整的代码:
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
class lfsr {
int y, xx, polyLoc, n, end, f, e, m, c, l, g;
boost::dynamic_bitset<> inpSeq(5);
boost::dynamic_bitset<> operSeq(5);
boost::dynamic_bitset<> bit(5);
vector <int> xorArray;
vector <int> keyReg;
polyLoc = 320;
while(polyLoc>0)
{
xorArray.push_back(polyLoc%10);
polyLoc/=10;
}
sort(xorArray.rbegin(), xorArray.rend());
operSeq = inpSeq;
keyReg.push_back(inpSeq[0]);
int x = xorArray[0];
do {
for (unsigned int r = 1; r < xorArray.size(); r++)
{
bit[seq_end] = operSeq[x];
y = xorArray[r];
bit[seq_end] = bit[seq_end] ^ operSeq[y];
}
operSeq >>= 1;
operSeq[seq_end] = bit[seq_end];
keyReg.push_back(operSeq[0]);
turnCount ++;
}
while ((operSeq != inpSeq) && (turnCount < 1024));
for ( unsigned int i = 0; i < keyReg.size(); i++)
{
if (keyReg[i]==1)
{
m = m + int(pow(2,i));
}
n = p*q;
f = (p-1)*(q-1);
for (int k = 0; end < 1; k++)
{
if ( (1+k*f)%d == 0)
{
end = 2;
e = (1+(k*f))/d;
}
}
g = int(pow(m,e));
c = g%n;
public:
rsa (int, int, int, boost::dynamic_bitset);
int key () { return (c); }
};
lfsr::lfsr() //Constructor
{
y = 0;
turnCount = 0;
xx = 0;
polyLoc = 0;
n = 0;
end = 0;
f = 0;
e = 0;
m = 0;
c = 0;
l = 0, g = 0;
};
lfsr::rsa (int x, int y, int z, boost::dynamic_bitset <5> initSeq)
{
p = x;
q = y;
d = z;
inpSeq = initSeq;
}
int main ()
{
lfsr public_key, private_key;
public_key.rsa (29, 41, 74, 00111);
private_key.rsa (43, 89, 73, 01011);
cout << "Public key is: " << public_key.key() << endl;
cout << "Private key is: " << private_key.key() << endl;
}
在您的类的前半部分,似乎有直接放在class
作用域下的语句。
需要定义成员函数来保存这些代码,然后在类上调用这些成员函数。
对于变量,它们是在成员函数内部还是外部声明,取决于它们是需要持久化还是仅仅用于临时存储(用于计算)。
相关文章:
- C4204:使用的非标准扩展:非常量聚合初始值设定项
- 在双重继承的情况下如何处理非标准构造函数
- CMake 不编译具有非标准扩展名的文件
- CMake 包含非 cmake 库的第三方标头
- 定义具有非标准签名的自定义映射比较器
- 我想获取点的属性,它报告错误 C3867:"point::output_x":非标准语法;使用"&"创建指向成员的指针
- 非标准语法,使用 & 创建指向成员的指针
- 在Qt中链接具有非标准名称的lib文件
- C++将包含非人类可读数据的字符串转换为 200 双精度
- 非标准语法使用 '&' 创建指向成员 C++ 的指针
- WINAPI EnumWindowsProc:非标准语法;使用 & 创建指向成员的点
- Vulkan-hpp 是reinterpret_casting非标准布局类到另一个类.这合法吗?
- 'cv::Mat::type':非标准语法;使用 '&' 创建指向成员的指针
- registerPointPickingCallback (PCLViewer::callback_Test,(void*)&viewer);返回 C3687 非标准语法;使用"&"创建指向成员的指针
- 错误 C4839:非标准地使用类 'ATL::CW2AEX<520>' 作为可变参数函数的参数
- C++ Visual Studio 2015:非标准语法;使用 '&' 创建指向成员的指针
- 将NetBeans配置为调试包含非标准库的C 程序
- 在结构中,文件名可以包含非标准字符
- 符合标准的编译器是否可以拒绝包含非多态类型向下转换dynamic_cast代码
- 我必须在c++中的类定义中包含非标准库吗?