2011-06-14 4 views
0

저는 C++/구문 분석을 처음 사용하기 때문에 xsd 파일을 자동 생성 된 cpp 및 헤더 파일로 변환합니다. xml 파일 (xmlfilename)의 요소 (멤버 함수)에 액세스하려고하면 "기본 표현식이 누락되기 전에 '->'토큰 '이라는 오류가 발생합니다.C++/구문 분석 : 오류 : '->'토큰 앞에 예상 기본 표현식.이 오류를 해결하는 방법 .. ..?

내 코드 :

#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; 
} 

컴파일러 출력 :

[email protected]:~/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 

사람이 기본 표현 오류가 무엇을 설명 할 수 있습니까? 어떻게 해결할 수 있습니까?

자세한 내용 : 내가 사전에 잘못된 PLS를 어떤 하나의 가이드 me..Thanks 나는 아무 생각이

#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()); 

} 

나는 그게 오류가 아닙니다 내기 기꺼이

+0

여기서'n()'이 선언 되었습니까? – iammilind

+0

':: SelftTest :: MH'와':: SelfTest :: MH_'의 차이점은 무엇입니까? ':: std :: auto_ptr ::: SelfTest :: MH> xsd (new :: SelfTest :: MH (xmlFilename, xml_schema :: flags :: dont_validate));'? –

+0

정보가 충분하지 않습니다. –

답변

1

xsd은 try 블록에서 나갈 때 범위를 벗어납니다. 이 같은 시도에 cout 이동하십시오 : auto_ptr은의

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; 
} 

작업은 던져하지 보장됩니다. 당신이 당신의 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을 반환해야합니다.

+0

고마워요 .. 진짜 실수를 저에게 ....... – Balamurugan

+0

@Bala Don 그것이 당신을 위해 그것을 해결한다면 당신도 대답을 받아 들일 수 있다는 것을 잊지 마십시오. – greatwolf

2

알았어. 항상 으로 시작하는 컴파일러 오류에 대해 먼저 오류가 발생합니다. 후속 오류는 이전 오류의 부작용 일 수 있습니다.

이 경우 컴파일러는 분명히 강조한 행에 xsd이 무엇인지 알지 못합니다. 컴파일러 에 선언 된 문제가 xsd 이었으므로 해당 줄에 대해보고 된 컴파일러 오류에주의를 기울여야합니다. xsd 선언 이전의 줄에 잊어 버린 세미콜론과 같이 실제 오류가 더 일찍 나타날 수도 있습니다. 또는 컴파일러가 해당 행에서 언급 한 유형 중 하나를 인식하지 못할 수도 있습니다. auto_ptr 클래스는 메모리 헤더에서 제공됩니다. 그거 포함 시켰어? 아마도 MHauto_ptr 형식 매개 변수로 언급했을 때 밑줄을 생략했을 수도 있습니다.

+0

자세한 내용을 추가하십시오 pls는보세요 – Balamurugan

관련 문제