boost::dynamic_bitset initialize with size error

31 Views Asked by At

I use dynamic_bitset<> c(n); with unsigned long int n; before it. But the compiler show me that:error: 'n' is not a type. Please tell me why~ Thanks a lot.

Below is my code. It's a project to solve boolean SAT problem with .cnf file as its input file Anyway, the most important part is I can't initialize it with the length I want.

My g++ version is 10.5.0 and I compile my program in Ubuntu 20.04

#include <iostream>
#include <cmath>
#include <boost/dynamic_bitset.hpp>
#include <vector>
#include <fstream>

#define DEBUG
#define dybitset dynamic_bitset

using namespace std;
using namespace boost;

unsigned long int n;
unsigned long int cl;

class CNF{
    public:
        dynamic_bitset<> c(n);
        dybitset<>_c(n);


        void reset(CNF A){
            A.c.resize(n);
            A._c.resize(n);
        }

        bool is_unit(dybitset<> c){
            return (c.count()+_c.count())==1?1:0;
        }

    private:

};

vector<CNF> clause(cl);

void input_file(char* argv){
    ifstream fin;
    fin.open(argv,ios::in);
    if(fin){cout << "File successfully opened\n";}
    fin.ignore(6);
    fin >> n;
    fin >> cl;
    cout << n << " " << cl << "\n";
    for(unsigned long int i = 0; i < cl; i++){
        cout << "for line "<<i+1<<"\n";
        CNF A;
        int in = 0;
        fin >> in;
        while(in!= 0){
            if(in>0){
                cout << "set "<< in-1 <<" 1\n";
                A.c.set(in-1);
            }else{
                in*=-1;
                cout << "set ~"<< in-1 <<" 1\n";
                A._c.set(in-1);
            }
            fin >> in;
        }
        clause.push_back(A);
    }
    fin.close();

};
void output_file(char* argv){
    ofstream fout;
    fout.open(argv,ios::out);
    if(fout){cout << "File successfully opened\n";}
};

void printcl(){
    #ifdef DEBUG
    dybitset<> A(0);
    for(unsigned long int i = 0; i<clause.size();i++){
        cout << (clause[i].c|A)<<"\n";
        cout << (clause[i]._c|A)<<"\n";
        cout << "\n";
    }
    #endif // DEBUG
}

int main(int argc, char *argv[]){
    input_file(argv[1]);
    output_file(argv[2]);
    printcl();
    return 0;
}

BTW I also update my gcc version but it seems to give no help. Thanks everyone's help. This is my first time post a problem on stackoverflow. Also, My mother language is not English. If there's any problem on understanding my problem, I feel so sorry and apologize for it.

0

There are 0 best solutions below