错误:'if'之前的预期primary-expression

时间:2015-11-14 04:42:55

标签: c++ macros libxml2

这是我的代码,我不知道'if'附近哪里出错,c中的“primary-expression”是什么?

xml_parser.h

#define xpath(smth, exp) if (sizeof(*smth) == sizeof(xmlNode)) { xpath_node((xml_node_ptr)smth, exp); } else{ xpath_doc((xml_doc_ptr)smth, exp); }

xml_node_ptr *xpath_node(xml_node_ptr n, str exp);

xml_node_ptr *xpath_doc(xml_doc_ptr n, str exp);

xml_parser_test.cpp

TEST_F(XmlParserTest, xpath2) {
    xml_node_ptr n = xpath(d, "/html/body");
    xpath(n, "/div");
}

这是我的输出:

/home/roroco/Dropbox/rbs/ro_sites/c/xml_parser_test.cpp: In member function ‘virtual void XmlParserTest_xpath2_Test::TestBody()’:
/home/roroco/Dropbox/rbs/ro_sites/c/xml_parser.h:17:26: error: expected primary-expression before ‘if’
 #define xpath(smth, exp) if (sizeof(*smth) == sizeof(xmlNode)) { xpath_node((xml_node_ptr)smth, exp); } else{ xpath_doc((xml_doc_ptr)smth, exp); }
                          ^
/home/roroco/Dropbox/rbs/ro_sites/c/xml_parser_test.cpp:26:22: note: in expansion of macro ‘xpath’
     xml_node_ptr n = xpath(d, "/html/body");
                  ^

我的完整资料来源为here

1 个答案:

答案 0 :(得分:2)

您的代码几乎已扩展为

$ http OPTIONS http://127.0.0.1:8000/todos/ Origin:http://www.someorigin.com
HTTP/1.0 200 OK
Access-Control-Allow-Headers: x-requested-with, content-type, accept, origin, authorization, x-csrftoken, user-agent, accept-encoding
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 86400
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Date: Sat, 14 Nov 2015 04:45:37 GMT
Server: WSGIServer/0.1 Python/2.7.10
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN

由预处理器。很明显这是错的。要回答第二个问题,EMP_ID EMP_FirstName EMP_LastName 是C ++语法中预期的非终端。主要表达式类似于算术,函数调用等。