Public Group

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.

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 thing12			}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 on other sites
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 on other sites
Guessing, but should root be a Node* instead, or the iterator be Iterator<ticpp::Element> ?

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 on other sites
Quote:
 Original post by sprite_houndGuessing, but should root be a Node* instead, or the iterator be Iterator ?

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 silvermacecan 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.cppF:\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 silvermaceI 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 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 on other sites
Quote:
 Original post by nobodynewsI 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 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 thing12			}13		}`

1. 1
2. 2
3. 3
frob
12
4. 4
5. 5

• 13
• 14
• 65
• 14
• 15
• Forum Statistics

• Total Topics
632130
• Total Posts
3004286

×