【c++】error 某方法 declared as a 'virtual' field

来源:互联网 发布:淘宝客佣金扣除红包吗 编辑:程序博客网 时间:2024/04/30 00:45

参考    http://stackoverflow.com/questions/889581/why-c-compiler-gcc-thinks-function-is-virtual-field




I get that error when the first parameter doesn't make sense to it. Check thatEvaluator is known as type:

struct A {    virtual void* b(nonsense*, string*);};=> error: 'b' declared as a 'virtual' fieldstruct A {    virtual void* b(string*, nonsense*);};=> error: 'nonsense' has not been declared

To find out whether something is a object or function declaration, the compiler sometimes has to scan the whole declaration. Any construct within the declaration that could possibly form a declaration is taken to be a declaration. If not, then any such construct is taken to be an expression. GCC apparently thinks because nonsense is no valid type, it can't be a valid parameter declaration, and thus falls back treating the whole declaration as a field (note that it says in additionerror: expected ';' before '(' token ) . Same thing in local scope

int main() {    int a;    // "nonsense * a" not treated as declaration    void f(nonsense*a);}=> error: variable or field 'f' declared voidint main() {    // "nonsense * a" treated as parameter declaration    typedef int nonsense;    void f(nonsense*a);}=> (compiles successfully)

0 0
原创粉丝点击