简体   繁体   中英

Expected primary-expression before various tokens

The following code:

class queuenode {
public:
    queuenode();
    queuenode(cargo *mydata);
    ~queuenode() {delete cargo;} //Queuenodes delete their cargo on destruction - note that queuenodes DON'T free their neighbour, that's up to the queue class
public:
    queuenode *next;
    int pri; //this should always be equal to our cargo's pri
    cargo *data;
};

queuenode::queuenode(void) {
    next= (queuenode *) NULL; 
    cargo = (cargo *) NULL; //default const creates a null queuenode - pri is left undefined
}

queuenode::queuenode(cargo *mydata) {
    //Convert constr creates a queuenode wrapping a cargo, also setting pri to its pri
    data=mydata; 
    pri=mydata->pri; 
    next=(queuenode *) NULL;
}

gives me the following errors:

 pq_linkedlist.cpp: In destructor 'queuenode::~queuenode()': pq_linkedlist.cpp:19:28: error: expected primary-expression before ';' token pq_linkedlist.cpp: In constructor 'queuenode::queuenode()': pq_linkedlist.cpp:28:8: error: expected unqualified-id before '=' token 

I have no idea what's happening or why. There's all sorts of people with the same error message on the internet but all their problems seem to have to do with extra semicolons, and I'm pretty sure I don't have any.

~queuenode() {delete cargo;}

Should be:

~queuenode() {delete data;}

cargo is the type, data is the variable. Saying delete cargo makes as much sense as saying delete int .

Similarly this line is wrong:

cargo = (cargo *) NULL;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM