Visualizzazione dei risultati da 1 a 6 su 6

Discussione: [c++] Errore c2011

  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    81

    [c++] Errore c2011

    Ciao a tutti,
    Sto provando ad eseguire il seguente codice:
    codice:
    #include "stdafx.h"
    
    #include <xercesc/util/PlatformUtils.hpp>
    #include <xercesc/sax2/SAX2XMLReader.hpp>
    #include <xercesc/sax2/XMLReaderFactory.hpp>
    #if defined(XERCES_NEW_IOSTREAMS)
    #include <fstream>
    #else
    #include <fstream.h>
    #endif
    #include <xercesc/util/OutOfMemoryException.hpp>
    
    using namespace std;
    
    // ---------------------------------------------------------------------------
    //  Local helper methods
    // ---------------------------------------------------------------------------
    void usage()
    {
        XERCES_STD_QUALIFIER cout << "\nUsage:\n"
                "    SAX2Count [options] <XML file | List file>\n\n"
                "This program invokes the SAX2XMLReader, and then prints the\n"
                "number of elements, attributes, spaces and characters found\n"
                "in each XML file, using SAX2 API.\n\n"
                "Options:\n"
                "    -l          Indicate the input file is a List File that has a list of xml files.\n"
                "                Default to off (Input file is an XML file).\n"
                "    -v=xxx      Validation scheme [always | never | auto*].\n"
                "    -f          Enable full schema constraint checking processing. Defaults to off.\n"
                "    -p          Enable namespace-prefixes feature. Defaults to off.\n"
                "    -n          Disable namespace processing. Defaults to on.\n"
                "                NOTE: THIS IS OPPOSITE FROM OTHER SAMPLES.\n"
                "    -s          Disable schema processing. Defaults to on.\n"
                "                NOTE: THIS IS OPPOSITE FROM OTHER SAMPLES.\n"
                "    -i          Disable identity constraint checking. Defaults to on.\n"
                "                NOTE: THIS IS OPPOSITE FROM OTHER SAMPLES.\n"
                "    -locale=ll_CC specify the locale, default: en_US.\n"
                "    -?          Show this help.\n\n"
                "  * = Default if not provided explicitly.\n"
             << XERCES_STD_QUALIFIER endl;
    }
    
    
    // ---------------------------------------------------------------------------
    //  Program entry point
    // ---------------------------------------------------------------------------
    int main(int argC, char* argV[])
    {
    
        // Check command line and extract arguments.
        if (argC < 2)
        {
            usage();
            return 1;
        }
    
        const char*                  xmlFile      = 0;
        SAX2XMLReader::ValSchemes    valScheme    = SAX2XMLReader::Val_Auto;
        bool                         doNamespaces = true;
        bool                         doSchema = true;
        bool                         schemaFullChecking = false;
        bool                         identityConstraintChecking = true;
        bool                         doList = false;
        bool                         errorOccurred = false;
        bool                         namespacePrefixes = false;
        bool                         recognizeNEL = false;
        char                         localeStr[64];
        memset(localeStr, 0, sizeof localeStr);
    
        int argInd;
        for (argInd = 1; argInd < argC; argInd++)
        {
            // Break out on first parm not starting with a dash
            if (argV[argInd][0] != '-')
                break;
    
            // Watch for special case help request
            if (!strcmp(argV[argInd], "-?"))
            {
                usage();
                return 2;
            }
             else if (!strncmp(argV[argInd], "-v=", 3)
                  ||  !strncmp(argV[argInd], "-V=", 3))
            {
                const char* const parm = &argV[argInd][3];
    
                if (!strcmp(parm, "never"))
                    valScheme = SAX2XMLReader::Val_Never;
                else if (!strcmp(parm, "auto"))
                    valScheme = SAX2XMLReader::Val_Auto;
                else if (!strcmp(parm, "always"))
                    valScheme = SAX2XMLReader::Val_Always;
                else
                {
                    XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl;
                    return 2;
                }
            }
             else if (!strcmp(argV[argInd], "-n")
                  ||  !strcmp(argV[argInd], "-N"))
            {
                doNamespaces = false;
            }
             else if (!strcmp(argV[argInd], "-s")
                  ||  !strcmp(argV[argInd], "-S"))
            {
                doSchema = false;
            }
             else if (!strcmp(argV[argInd], "-f")
                  ||  !strcmp(argV[argInd], "-F"))
            {
                schemaFullChecking = true;
            }
             else if (!strcmp(argV[argInd], "-i")
                  ||  !strcmp(argV[argInd], "-I"))
            {
                identityConstraintChecking = false;
            }
             else if (!strcmp(argV[argInd], "-l")
                  ||  !strcmp(argV[argInd], "-L"))
            {
                doList = true;
            }
             else if (!strcmp(argV[argInd], "-p")
                  ||  !strcmp(argV[argInd], "-P"))
            {
                namespacePrefixes = true;
            }
             else if (!strcmp(argV[argInd], "-special:nel"))
            {
                // turning this on will lead to non-standard compliance behaviour
                // it will recognize the unicode character 0x85 as new line character
                // instead of regular character as specified in XML 1.0
                // do not turn this on unless really necessary
                 recognizeNEL = true;
            }
             else if (!strncmp(argV[argInd], "-locale=", 8))
            {
                 // Get out the end of line
                 strncpy(localeStr, &(argV[argInd][8]), sizeof localeStr);
            }
            else
            {
                XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[argInd]
                    << "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
            }
        }
    
        //
        //  There should be only one and only one parameter left, and that
        //  should be the file name.
        //
        if (argInd != argC - 1)
        {
            usage();
            return 1;
        }
    
        // Initialize the XML4C2 system
        try
        {
            if (strlen(localeStr))
            {
                XMLPlatformUtils::Initialize(localeStr);
            }
            else
            {
                XMLPlatformUtils::Initialize();
            }
    
            if (recognizeNEL)
            {
                XMLPlatformUtils::recognizeNEL(recognizeNEL);
            }
        }
    
        catch (const XMLException& toCatch)
        {
            XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
                << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
            return 1;
        }
    
        //
        //  Create a SAX parser object. Then, according to what we were told on
        //  the command line, set it to validate or not.
        //
        SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
        parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces);
        parser->setFeature(XMLUni::fgXercesSchema, doSchema);
        parser->setFeature(XMLUni::fgXercesHandleMultipleImports, true);
        parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
        parser->setFeature(XMLUni::fgXercesIdentityConstraintChecking, identityConstraintChecking);
        parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, namespacePrefixes);
    
        if (valScheme == SAX2XMLReader::Val_Auto)
        {
            parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
            parser->setFeature(XMLUni::fgXercesDynamic, true);
        }
        if (valScheme == SAX2XMLReader::Val_Never)
        {
            parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
        }
        if (valScheme == SAX2XMLReader::Val_Always)
        {
            parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
            parser->setFeature(XMLUni::fgXercesDynamic, false);
        }
    
        //
        //  Create our SAX handler object and install it on the parser, as the
        //  document and error handler.
        //
        SAX2CountHandlers handler;
        parser->setContentHandler(&handler);
        parser->setErrorHandler(&handler);
    
        //
        //  Get the starting time and kick off the parse of the indicated
        //  file. Catch any exceptions that might propogate out of it.
        //
        unsigned long duration;
    
        bool more = true;
        XERCES_STD_QUALIFIER ifstream fin;
    
        // the input is a list file
        if (doList)
            fin.open(argV[argInd]);
    
        if (fin.fail()) {
            XERCES_STD_QUALIFIER cerr <<"Cannot open the list file: " << argV[argInd] << XERCES_STD_QUALIFIER endl;
            return 2;
        }
    
        while (more)
        {
            char fURI[1000];
            //initialize the array to zeros
            memset(fURI,0,sizeof(fURI));
    
            if (doList) {
                if (! fin.eof() ) {
                    fin.getline (fURI, sizeof(fURI));
                    if (!*fURI)
                        continue;
                    else {
                        xmlFile = fURI;
                        XERCES_STD_QUALIFIER cerr << "==Parsing== " << xmlFile << XERCES_STD_QUALIFIER endl;
                    }
                }
                else
                    break;
            }
            else {
                xmlFile = argV[argInd];
                more = false;
            }
    
            //reset error count first
            handler.resetErrors();
    
            try
            {
                const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
                parser->parse(xmlFile);
                const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
                duration = endMillis - startMillis;
            }
            catch (const OutOfMemoryException&)
            {
                XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
                errorOccurred = true;
                continue;
            }
            catch (const XMLException& e)
            {
                XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n"
                    << "Exception message is:  \n"
                    << StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
                errorOccurred = true;
                continue;
            }
    
            catch (...)
            {
                XERCES_STD_QUALIFIER cerr << "\nUnexpected exception during parsing: '" << xmlFile << "'\n";
                errorOccurred = true;
                continue;
            }
    
    
            // Print out the stats that we collected and time taken
            if (!handler.getSawErrors())
            {
                XERCES_STD_QUALIFIER cout << xmlFile << ": " << duration << " ms ("
                    << handler.getElementCount() << " elems, "
                    << handler.getAttrCount() << " attrs, "
                    << handler.getSpaceCount() << " spaces, "
                    << handler.getCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl;
            }
            else
                errorOccurred = true;
        }
    
        if (doList)
            fin.close();
    
        //
        //  Delete the parser itself.  Must be done prior to calling Terminate, below.
        //
        delete parser;
    
        // And call the termination method
        XMLPlatformUtils::Terminate();
    
        if (errorOccurred)
            return 4;
        else
            return 0;
    
    }
    Posto anche il contenuto del file stdafx.h
    codice:
    // stdafx.h : file di inclusione per file di inclusione di sistema standard
    // o file di inclusione specifici del progetto utilizzati di frequente, ma
    // modificati raramente
    //
    
    #pragma once
    
    #include "targetver.h"
    #include "SAX2Count.hpp"
    #include "SAX2CountHandlers.hpp"
    
    
    #include <stdio.h>
    #include <tchar.h>
    Ho incluso all'interno del progetto i file :
    - SAX2Count.hpp
    -SAX2CountHandlers.hpp

    Ma quando vado a compilare viene sollevato il seguente errore:
    studio 2008\projects\prova2\prova2\sax2counthandlers.hpp( 31) : error C2011: 'SAX2CountHandlers': ridefinizione tipo 'class'
    c:\documents and settings\alessandra\documenti\visual studio 2008\projects\prova2\prova2\sax2counthandlers.hpp( 31): vedere la dichiarazione di 'SAX2CountHandlers'

    Da cosa può dipendere? GRazie

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,466
    Il compilatore indica degli errori nel file

    sax2counthandlers.hpp

    ma tu non ne mostri il sorgente ...
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    81
    Questo è il codice di SAX2CountHandlers.hpp:
    codice:
    /*
     * Licensed to the Apache Software Foundation (ASF) under one or more
     * contributor license agreements.  See the NOTICE file distributed with
     * this work for additional information regarding copyright ownership.
     * The ASF licenses this file to You under the Apache License, Version 2.0
     * (the "License"); you may not use this file except in compliance with
     * the License.  You may obtain a copy of the License at
     * 
     *      http://www.apache.org/licenses/LICENSE-2.0
     * 
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
    
    /*
     * $Id: SAX2CountHandlers.hpp 679377 2008-07-24 11:56:42Z borisk $
     */
    
    
    // ---------------------------------------------------------------------------
    //  Includes
    // ---------------------------------------------------------------------------
    #include <xercesc/sax2/Attributes.hpp>
    #include <xercesc/sax2/DefaultHandler.hpp>
    
    XERCES_CPP_NAMESPACE_USE
    
    class SAX2CountHandlers : public DefaultHandler
    {
    public:
        // -----------------------------------------------------------------------
        //  Constructors and Destructor
        // -----------------------------------------------------------------------
        SAX2CountHandlers();
        ~SAX2CountHandlers();
    
    
        // -----------------------------------------------------------------------
        //  Getter methods
        // -----------------------------------------------------------------------
        XMLSize_t getElementCount() const
        {
            return fElementCount;
        }
    
        XMLSize_t getAttrCount() const
        {
            return fAttrCount;
        }
    
        XMLSize_t getCharacterCount() const
        {
            return fCharacterCount;
        }
    
        bool getSawErrors() const
        {
            return fSawErrors;
        }
    
        XMLSize_t getSpaceCount() const
        {
            return fSpaceCount;
        }
    
    
        // -----------------------------------------------------------------------
        //  Handlers for the SAX ContentHandler interface
        // -----------------------------------------------------------------------
        void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs);
        void characters(const XMLCh* const chars, const XMLSize_t length);
        void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length);
        void startDocument();
    
    
        // -----------------------------------------------------------------------
        //  Handlers for the SAX ErrorHandler interface
        // -----------------------------------------------------------------------
    	void warning(const SAXParseException& exc);
        void error(const SAXParseException& exc);
        void fatalError(const SAXParseException& exc);
        void resetErrors();
    
    
    private:
        // -----------------------------------------------------------------------
        //  Private data members
        //
        //  fAttrCount
        //  fCharacterCount
        //  fElementCount
        //  fSpaceCount
        //      These are just counters that are run upwards based on the input
        //      from the document handlers.
        //
        //  fSawErrors
        //      This is set by the error handlers, and is queryable later to
        //      see if any errors occured.
        // -----------------------------------------------------------------------
        XMLSize_t       fAttrCount;
        XMLSize_t       fCharacterCount;
        XMLSize_t       fElementCount;
        XMLSize_t       fSpaceCount;
        bool            fSawErrors;
    };

  4. #4
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,466
    Sembra che la classe sia già dichiarata quando viene incontrata la riga

    class SAX2CountHandlers : public DefaultHandler

    Prova ad eliminare gli include dallo stdafx.h
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  5. #5
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    81
    Mi da un errore li questo tipo :
    prova2.obj : error LNK2019: riferimento al simbolo esterno "public: virtual void __thiscall SAX2CountHandlers::resetErrors(void)" (?resetErrors@SAX2CountHandlers@@UAEXXZ) non risolto nella funzione __catch$_main$0
    prova2.obj : error LNK2019: riferimento al simbolo esterno "public: virtual __thiscall SAX2CountHandlers::~SAX2CountHandlers(void)" (??1SAX2CountHandlers@@UAE@XZ) non risolto nella funzione __catch$_main$0
    prova2.obj : error LNK2019: riferimento al simbolo esterno "public: __thiscall SAX2CountHandlers::SAX2CountHandlers(void)" (??0SAX2CountHandlers@@QAE@XZ) non risolto nella funzione __catch$_main$0

    L'ho già incontrato e risolto una volta ma ora non riesco a capire a quale libreria si riferisce..

  6. #6
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,466
    In effetti manca il riferimento ad una libreria (un file .lib) ... devi vedere tu quale puo' essere ...
    No MP tecnici (non rispondo nemmeno!), usa il forum.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.