c ++ /解析:错误:\'->\'标记之前的预期主表达式如何解决此错误..?

如何解决c ++ /解析:错误:\'->\'标记之前的预期主表达式如何解决此错误..?

| 我是c ++ /解析的新手,我将xsd文件转换为自动生成的cpp和头文件。当我尝试访问xml文件(xmlfilename)的元素(成员函数)时,出现错误\“-> \'token \之前缺少主表达式。” 我的代码:
#include \"IMACSMsgHeaderType.h\"
#include<iostream>
#include<string>
#include <memory>

#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>

using namespace std;
using namespace SelfTest;

int main()
  {
 try{
   ::std::auto_ptr< ::SelfTest::MH > xsd (::SelfTest::MH_ (\"bala.xml\",::xml_schema::flags::dont_validate));
}
catch(const xml_schema::exception& e)
{
    cerr<<e.what()<<endl;        
}
cout<<xsd->n();
return 1;
}
编译器输出:
vmware@LSS01:~/Desktop/private> make
g++ -c test_classParsing.cpp 
test_classParsing.cpp: In function ‘int main()’:
test_classParsing.cpp:26: error: expected primary-expression before ‘->’ token
make: *** [.o] Error 1
谁能解释什么是主表达式错误?我该如何解决呢? 更多细节:
  #include <memory>    
  #include <algorithm> 
  #include <xsd/cxx/tree/exceptions.hxx>
  #include <xsd/cxx/tree/elements.hxx>
  #include <xsd/cxx/tree/containers.hxx>
  #include <xsd/cxx/tree/list.hxx>
  #include <xsd/cxx/xml/dom/parsing-header.hxx>
  #include \"IMACSTypes.h\"

 #include<iosfwd>
 #include<xercesc/dom/DOMDocument.hpp>
 #include<xercesc/dom/DOMErrorHandler.hpp>
 #include<xercesc/framework/XMLFormatter.hpp>
 #include<xsd/cxx/xml/dom/auto-ptr.hxx>

 namespace SelfTest
 {
    class MH: public ::xml_schema::type
   {
     public:
   // hdrSize
    // 
    typedef ::xml_schema::unsigned_int hdrSize_type;
    typedef ::xsd::cxx::tree::optional< hdrSize_type > hdrSize_optional;
    typedef ::xsd::cxx::tree::traits< hdrSize_type,char > hdrSize_traits;

const hdrSize_optional&
hdrSize () const;

hdrSize_optional&
hdrSize ();

void
hdrSize (const hdrSize_type& x);

void
hdrSize (const hdrSize_optional& x);

// a
// 
typedef ::SelfTest::MessageIDType a_type;
typedef ::xsd::cxx::tree::traits< a_type,char > a_traits;

const a_type&
a () const;

a_type&
a ();

void
a (const a_type& x);

void
a (::std::auto_ptr< a_type > p);

// b
// 
typedef ::SelfTest::DestinationType b_type;
typedef ::xsd::cxx::tree::traits< b_type,char > b_traits;

const b_type&
b () const;

b_type&
b ();

void
b (const b_type& x);

void
b (::std::auto_ptr< b_type > p);

// n
// 
typedef ::xml_schema::string n_type;
typedef ::xsd::cxx::tree::traits< n_type,char > n_traits;

const n_type&
n () const;

n_type&
n ();

void
n (const n_type& x);

void
n (::std::auto_ptr< n_type > p);
// Constructors.

MH (const a_type&,const b_type&,const n_type&,);

MH (const ::xercesc::DOMElement& e,::xml_schema::flags f = 0,::xml_schema::container* c = 0);

MH (const MH& x,::xml_schema::container* c = 0);

virtual MH*
_clone (::xml_schema::flags f = 0,::xml_schema::container* c = 0) const;

virtual 
~MH ();

// Implementation.
//
protected:
void
parse (::xsd::cxx::xml::dom::parser< char >&,::xml_schema::flags);

protected:
hdrSize_optional hdrSize_;
::xsd::cxx::tree::one< a_type > a_;
::xsd::cxx::tree::one< b_type > b_;
::xsd::cxx::tree::one< n_type > n_;
 };

  ::std::auto_ptr< ::SelfTest::MH >
   MH_ (const ::std::string& uri,const ::xml_schema::properties& p = ::xml_schema::properties ());

}
我不知道我哪里错了,请一个人来指导我。     

解决方法

        离开try块时,您的
xsd
超出范围。尝试将
cout
移入尝试,如下所示:
int main()
{
    try
    {
      std::auto_ptr< SelfTest::MH > 
      xsd( SelfTest::MH_(\"bala.xml\",xml_schema::flags::dont_validate) );
      cout << xsd->n();
    }
    catch(const xml_schema::exception& e)
    {
        cerr << e.what() << endl;        
    }

    return 0;
}
保证不会抛出auto_ptr的操作。因此,如果要限制try块的范围,也可以执行此操作:
int main()
{
    std::auto_ptr< SelfTest::MH > xsd;
    try
    {
      xsd.reset( SelfTest::MH_(\"bala.xml\",xml_schema::flags::dont_validate) );
    }
    catch(const xml_schema::exception& e)
    {
        cerr << e.what() << endl;        
    }
    if( xsd.get() )
      cout << xsd->n();

    return 0;
}
请注意,如果没有错误,您的“ 7”应返回0。     ,        我愿意打赌这不是您遇到的唯一错误。始终从列表中的第一个错误开始处理编译器错误;随后的错误可能只是先前错误的副作用。 在这种情况下,编译器显然不知道突出显示的行中的3。这表明编译器在
xsd
的声明上也有问题,因此请集中精力为该行报告编译器错误。请记住,实际错误可能更早,例如在
xsd
声明之前的行中遗忘了分号。也许编译器无法识别您在那一行中提到的一种类型。
auto_ptr
类来自内存头;你包括了吗?当您将
MH
作为
auto_ptr
类型参数时,可能省略了下划线。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-