0

私はc++/ parsingを初めて使用し、xsdファイルを自動生成されたcppおよびヘッダーファイルに変換します。xmlファイル(xmlfilename)の要素(メンバー関数)にアクセスしようとすると、「'->'トークンの前にプライマリ式がありません」というエラーが発生します。

私のコード:

#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::flags f = 0,
    ::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, ::xml_schema::flags f = 0,const ::xml_schema::properties& p = ::xml_schema::properties ());

}

私はどこが間違っているのか分かりませんpls誰かが私を導きます..事前に感謝します

4

2 に答える 2

2

あなたが得た唯一のエラーではないと確信しています。リストの最初のエラーから始めて、常にコンパイラ エラーに取り組みます。後続のエラーは、以前のエラーの副作用にすぎない可能性があります。

この場合、コンパイラはxsd、強調表示した行に何があるかを明らかに認識していません。これは、コンパイラが の宣言に問題を抱えていたことを示唆しているxsdため、代わりにその行で報告されたコンパイラ エラーに注意を向けてください。xsd宣言の前の行でセミコロンを忘れているなど、実際のエラーはさらに早い段階にある可能性があることに注意してください。または、その行で言及したタイプのいずれかをコンパイラが認識しない可能性があります。auto_ptrクラスはメモリ ヘッダーから取得れます。あなたはそれを含めましたか?型パラメーターMHとして言及したときにアンダースコアを省略した可能性があります。auto_ptr

于 2011-06-14T05:43:08.477 に答える
1

tryxsdブロックを離れると、範囲外になります。次のようにtry に移動してみてください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;
}

mainエラーがない場合は 0 を返す必要があることに注意してください。

于 2011-06-14T07:03:00.853 に答える