简体   繁体   English

在各种令牌之前预期的主要表达

[英]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. cargo是类型, data是变量。 Saying delete cargo makes as much sense as saying delete int . delete cargodelete int一样有意义。

Similarly this line is wrong: 同样,这一行是错误的:

cargo = (cargo *) NULL;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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