2
如何使用元素和属性的基于范围的循环来做这种工作?基于循环实现的基于循环实现的C++中的XML元素类11
#include <list>
#include "XMLAttribute.h"
namespace XML
{
class Element
{
private:
typedef std::list<Attribute> attribute_container;
typedef std::list<Element> element_container;
public:
XMLElement();
bool has_attributes() const;
bool has_elements() const;
bool has_data() const;
const std::string &name() const;
const std::string &data() const;
private:
std::string _name;
std::string _data;
attribute_container _attributes;
element_container _elements;
};
}
我想能够使用这样的:
for (XML::Element &el : element) { .. }
for (XML::Attribute &at : element) { .. }
并阻止类似for (auto &some_name : element) { .. } //XML::Element or XML::Attribute?
。
像这样实现它还是应该改变我的设计?
精彩回答!谢谢! – 2012-07-09 18:16:13