开发者

TinyXML #include problem... Using libraries

Hey, i'm really 开发者_StackOverflow中文版trying to get TinyXML to at least read a file but it says "main.cpp:8: error: ‘TiXMLDocument’ was not declared in this scope"

This is the code im using:

TiXMLDocument("demo.xml");

Ideally i want to read able to read files and output the XML so i also tried this code i found online in a tutorial

#include <iostream>

#include "tinyxml.h"
#include "tinystr.h"

void dump_to_stdout(const char* pFilename)
{
    TiXmlDocument doc(pFilename);
    bool loadOkay = doc.LoadFile();
    if (loadOkay)
    {
        printf("\n%s:\n", pFilename);
        dump_to_stdout( &doc ); // defined later in the tutorial
    }
    else
    {
        printf("Failed to load file \"%s\"\n", pFilename);
    }
}

int main(void)
{
    dump_to_stdout("demo.xml");
    return 0;
}

And the errors I'm getting now are:

main.cpp: In function ‘void dump_to_stdout(const char*)’:
main.cpp:13: error: cannot convert ‘TiXmlDocument*’ to ‘const char*’ for argument ‘1’ to ‘void dump_to_stdout(const char*)’

If it helps im on a mac, ive tried compiling in terminal as well as textmate. I also tried to compile the cpp files for TinyXML separately before compiling main.cpp and i have no idea why i cant print out demo.xml let alone read it.


  1. It's called TiXmlDocument, not TiXMLDocument
  2. You can't call a function that you haven't declared yet. Since you're trying to call an undeclared overload of dump_to_stdout, the compiler assumes you want to call the version that takes const char * and fails.


dump_to_stdout( &doc ); // defined later in the tutorial

Here's your problem.

  1. dump_to_stdout takes a const char* which TiXmlDocument is definitely not.
  2. You're already in that function, so assuming the file loads you'll have infinite recursion.
  3. It doesn't matter that you've got one defined later that takes a TiXmlDocument. At this point, the only dump_to_stdout that exists is the one you're in, hence the error. Forward declare the one you want before this function, e.g: void dump_to_stdout(TiXmlDocument*);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜