C++ 在C++;班

C++ 在C++;班,c++,class,boost-dynamic-bitset,C++,Class,Boost Dynamic Bitset,下面的代码没有编译,我确信问题在于如何声明动态位集inpSeq并将其赋值,为了将位赋值给该位集,我这样编码 usr1.set (11, 5, 23, 00001); 对于在我使用的成员函数集中声明inpSeq: void set (int , int , int, boost::dynamic_biset <>); void集(int,int,int,boost::dynamic_biset); 另外,其他3个动态位集的声明在某种程度上是错误的,我不知道为什么,我声明它们就像它

下面的代码没有编译,我确信问题在于如何声明动态位集inpSeq并将其赋值,为了将位赋值给该位集,我这样编码

usr1.set (11, 5, 23, 00001);
对于在我使用的成员函数集中声明inpSeq:

void set (int , int , int, boost::dynamic_biset <>);
void集(int,int,int,boost::dynamic_biset);
另外,其他3个动态位集的声明在某种程度上是错误的,我不知道为什么,我声明它们就像它们在main中一样,不知道它们在一个类中是否或如何不同

以下是完整的代码:

#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <boost/dynamic_bitset.hpp>

using namespace std;
class rsa {
 protected:
 int  polyLoc, x, y, p, q, d, m, n, f, e, c, end, k;
 boost::dynamic_bitset<> inpSeq (5);
 boost::dynamic_bitset<> operSeq(5);
 boost::dynamic_bitset<> bit(5);
 vector <int> xorArray;
 vector <int> keyReg;
 public:
 rsa () : polyLoc(3210), x(0), y(0), n(0), e(0), c(0), k(0), end(0), f(0) {};
 void set (int , int , int, boost::dynamic_biset <>);
 int key () {
while(polyLoc>0)
 {
  xorArray.push_back(polyLoc%10);
  polyLoc/=10;
 }
 sort(xorArray.rbegin(), xorArray.rend());
 operSeq = inpSeq;
 keyReg.push_back(inpSeq[0]);
  x = xorArray[0];
  do {
  for (unsigned int r = 1; r < xorArray.size(); r++)
  {
  bit[4] = operSeq[x];
  y = xorArray[r];
  bit[4] = bit[4] ^ operSeq[y];
  }
  operSeq >>= 1;
  operSeq[4]  = bit[4];
  keyReg.push_back(operSeq[0]);
 }
 while ((operSeq != inpSeq));
 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 (k ; end < 1; k++)
 {
  if ((1+k*f)%d==0) 
   {
    end = 2;
    e = (1+k*f)/d;
   }
 }
 c = int(pow(m,e))%n;
 return c;}
 };

void rsa::set(int p_, int q_, int d_, boost::dynamic_biset <> m_ (5))
 {
  p = p_;
  q = q_;
  d = d_;
  inpSeq = m_;
 }

class public_key : public rsa {
 public:
 public_key () : rsa () {} ;
};

class private_key : public rsa {
 public:
  private_key () : rsa () {} ;
};

int main()
{
public_key usr1, usr2, usr3;
private_key usr1r, usr2r, usr3r;
usr1.set (11, 5, 23, 00001);
usr2.set (13, 7, 97, 00010);
usr3.set (11, 17, 997, 00011);
usr1r.set (17, 7, 51, 10011);
usr2r.set (11, 17, 51, 10110);
cout << "Public key of user 1: " << usr1.key() << endl;
cout << "Public key of user 2: " << usr2.key() << endl;
cout << "Public key of user 3: " << usr3.key() << endl;
cin.get();
return 0;
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
类rsa{
受保护的:
int polyLoc,x,y,p,q,d,m,n,f,e,c,end,k;
boost::动态_位集inpSeq(5);
boost::动态_位集操作序列(5);
boost::动态_位集位(5);
矢量X射线;
向量keyReg;
公众:
rsa():polyLoc(3210),x(0),y(0),n(0),e(0),c(0),k(0),end(0),f(0){};
void集(int,int,int,boost::dynamic_biset);
int键(){
而(多段曲线>0)
{
xorArray.push_back(多段代码%10);
polyLoc/=10;
}
排序(xorArray.rbegin(),xorArray.rend());
operSeq=inpSeq;
keyReg.push_back(inpSeq[0]);
x=xorArray[0];
做{
for(unsigned int r=1;r>=1;
operSeq[4]=位[4];
keyReg.push_back(操作顺序[0]);
}
而((operSeq!=inpSeq));
for(无符号整数i=0;icout您需要初始化
成员初始化列表中的
动态\u位集
成员

class rsa 
{
    public:
        typedef boost::dynamic_bitset<> BitSet;

    protected:
        int  polyLoc, x, y, p, q, d, m, n, f, e, c, end, k;
        BitSet inpSeq;
        BitSet operSeq;
        BitSet bit;
        vector <int> xorArray;
        vector <int> keyReg;
    public:
        rsa () : polyLoc(3210), x(0), y(0), n(0), e(0), c(0), k(0), end(0), f(0),
                        inpSeq(5), operSeq(5), bit(5) {}

        void set (int , int , int, const BitSet&);
     //...
};
类rsa
{
公众:
typedef boost::动态_位集位集;
受保护的:
int polyLoc,x,y,p,q,d,m,n,f,e,c,end,k;
位集inpSeq;
位集操作序列;
位集位;
矢量X射线;
向量keyReg;
公众:
rsa():多段(3210),x(0),y(0),n(0),e(0),c(0),k(0),end(0),f(0),
inpSeq(5),operSeq(5),位(5){
空集(int,int,int,const位集&);
//...
};

每当您有一个成员需要除默认构造以外的任何构造时,您必须在成员初始化列表中对其进行初始化。我在上面所做的更改是使用一个名为
位集的方便的typedef
。此更改可能会使您更清楚地了解如何处理需要初始化的类型。

谢谢,这减少了这个错误很大。在成员函数集中定义的位集是否正确?现在我在名称空间“Boost”中得到“DyrimeIsBiSET”,不命名类型空洞集(int,int,int,Boost::DyjixBieTe&);^损坏。cc:18:42:错误:ISO C++禁止声明“参数”,没有类型。[-fpPermissive]void set(int,int,int,const boost::dynamic_biset&);@mohamedhamed-您拼错了
dynamic_位集
。请查看更新的答案。@mohamedhamed-我键入了boost::dynamic_位集。希望您能看到错误您在使用typedef而不是未定义的名称时所做的。最后一个错误,关于将位分配给动态位集:调用“public_key::set(int,int,int,int)”usr1.set(11,5,23,00001)时没有匹配函数^damage.cc:81:27:注意:候选项是:damage.cc:59:6:注意:void rsa::set(int,int,int,const boost::dynamic_bitset&)void rsa::set(int p,int q,int d,const boost::dynamic_bitset&)^damamage.cc:59:6:注意:参数4从'int'到'const boost::dynamic_bitset&'没有已知的转换
class rsa 
{
    public:
        typedef boost::dynamic_bitset<> BitSet;

    protected:
        int  polyLoc, x, y, p, q, d, m, n, f, e, c, end, k;
        BitSet inpSeq;
        BitSet operSeq;
        BitSet bit;
        vector <int> xorArray;
        vector <int> keyReg;
    public:
        rsa () : polyLoc(3210), x(0), y(0), n(0), e(0), c(0), k(0), end(0), f(0),
                        inpSeq(5), operSeq(5), bit(5) {}

        void set (int , int , int, const BitSet&);
     //...
};