Jump to content
  • Advertisement
Sign in to follow this  
chiranjivi

beginner tinyxml++ question

This topic is 2948 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Trying to write a very simple game that will read from an .xml file which contains details of all guns usable in the game. I'm using TinyXML++ for this. Here's the function that (supposedly) reads the .xml file:


1 void load_guns ( ticpp::Document doc ) {
2
3 cout << "loading guns.xml\n";
4
5 ticpp::Element* root = doc.FirstChildElement();
6
7 try {
8 ticpp::Iterator< ticpp::Node > child;
9 for ( child = child.begin( root ); child != child.end(); child++ ) {
10 if ( child->Value() == "gun" ) {
11 // do an thing
12 }
13 }
14 } catch ( ticpp::Exception& ex ) {
15 cout << "u mad\n";
16 }
17 }




This code doesn't compile. Now, this is par for the course for most things that I code, but I'm kind of confused here because the error I get comes from line 9, and reads:

error: 'class ticpp::Iterator<ticpp::Node>' has no member named 'begin'

... and the code that is causing that error is a direct copy-paste from TinyXML++'s own documentation (ticpp iterator documentation). What am I doing wrong here that this doesn't work...?

Share this post


Link to post
Share on other sites
Advertisement
A hopeful bump.

After searching these forums for 'ticpp', I've found instances of people using this code with no problems (cf. this post), so I must be doing something really stupid here that is very obvious to anyone who isn't a rank beginner. What is it?

Share this post


Link to post
Share on other sites
can you paste the whole error? I think there's some vital info missing from the error - maybe include the build log in source tags. I would guess its a missing header, but that seems really unlikely as TiXML++ is like all of 2 header files..

My first suspicion was that child.begin( const Node* p ) wasn't being selected by the compiler because root is of type Element but its clearly obvious (to the compiler) that Element implements Node so that can't be it..

Share this post


Link to post
Share on other sites
Quote:
Original post by sprite_hound
Guessing, but should root be a Node* instead, or the iterator be Iterator<ticpp::Element> ?


I'm pretty sure it isn't an issue with the code because, to reiterate, this is a straight copy and paste of code from the official TinyXML++ tutorial; also, other people seem to have made it work just fine :(

Quote:
Original post by silvermace
can you paste the whole error? I think there's some vital info missing from the error - maybe include the build log in source tags.


This is the whole of the build log from CodeBlocks:

-------------- Build: Debug in TiCPP ---------------

Compiling: main.cpp
F:\Dev\TiCPP\main.cpp: In function `void load_guns(ticpp::Document)':
F:\Dev\TiCPP\main.cpp:42: error: 'class ticpp::Iterator<ticpp::Node>' has no member named 'begin'
Process terminated with status 1 (0 minutes, 7 seconds)
1 errors, 0 warnings




Quote:
Original post by silvermace
I would guess its a missing header, but that seems really unlikely as TiXML++ is like all of 2 header files..


Yeah, this is what I don't understand. Ordinarily I would assume that I had messed up linkers or something like that but AFAIK you just have to #include the necessary files and that's that?

Share this post


Link to post
Share on other sites
I looked in the ticpp.h header and saw this as the first non-comment is "#ifdef TIXML_USE_TICPP"

So if you don't define that anywhere the code could be doing anything.

Share this post


Link to post
Share on other sites
Quote:
Original post by nobodynews
I looked in the ticpp.h header and saw this as the first non-comment is "#ifdef TIXML_USE_TICPP"

So if you don't define that anywhere the code could be doing anything.


I should probably have made this clear from the outset but yeah, I've defined that.

Share this post


Link to post
Share on other sites
just noticed, begin() returns T* not Iterator<T> ?? ie. lines 8 and 9:
8               ticpp::Iterator< ticpp::Node > child;
9 for ( child = child.begin( root ); child != child.end(); child++ ) {
10 if ( child->Value() == "gun" ) {
11 // do an thing
12 }
13 }

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!