#include <stdio.h>
extern "C" {
#include "dimacs_reader.h"
}
struct boolean{
int numvar;
int numclause;
int clause[numclause][numvar];
};
boolean *clauseptr;
int clauseindex;
void init(int numvars, int numclauses) {
// Callback function that gets passed to read_dimacs().
// Indicates start of a new expression with up to numvars variables
// and numclauses clauses.
clauseptr = new boolean;
clauseptr->numvar=numvars;
clauseptr->numclause=numclauses;
clauseptr->clause[numclauses][numvars];
clauseindex=0;
}
void add_clause(int numlits, int literals[]) {
// Callback function that gets passed to read_dimacs().
// The literals argument is an array of ints, numlits is its length.
// Each literal is the index (starting from 1) of a variable.
// Negative integers represent logical negations of variables.
clauseptr->clause[clauseindex][numlits];
for(int i=0; i<numlits ; i++){
clauseptr->clause[clauseindex][i] = literals[i];
}
clauseindex++;
}
char *classify() {
// Evaluate the current expression and return one of
// "satisfiable", "unsatisfiable" or "tautology".
return (char *) "unsatisfiable";
}
int main(int argc, char *argv[]) {
int i;
for (i = 1; i < argc; ++i) {
read_dimacs(argv[i], init, add_clause);
printf("%s: %s\n", argv[i], classify());
}
return 0;
}
我收到一个错误,说明在布尔结构中的numvar和numclause是静态数据成员。我试图使用我的结构中的2个int和数组来使用我的init函数存储一些数据。我错误地使用了指针吗? 我的init和add_clause函数使用一个名为read_dimacs的函数来解析.cnf文件,该函数还使用init和add_clause函数作为参数。
这是我的完整错误消息:
main.cpp:15:13: error: invalid use of non-static data member ‘boolean::numclause’
int numclause;
^
main.cpp:16:20: error: from this location
int clause[numclause][numvar];
^
main.cpp:14:13: error: invalid use of non-static data member ‘boolean::numvar’
int numvar;
^
main.cpp:16:31: error: from this location
int clause[numclause][numvar];
^
main.cpp: In function ‘void init(int, int)’:
main.cpp:30:13: error: ‘struct boolean’ has no member named ‘clause’
clauseptr->clause[numclauses][numvars];
^
main.cpp: In function ‘void add_clause(int, int*)’:
main.cpp:42:13: error: ‘struct boolean’ has no member named ‘clause’
clauseptr->clause[clauseindex][numlits];
^
main.cpp:44:14: error: ‘struct boolean’ has no member named ‘clause’
clauseptr->clause[clauseindex][i] = literals[i];