1 Replies - 314 Views - Last Post: 11 January 2013 - 03:10 AM Rate Topic: -----

#1 thomasrjones  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-January 13

Dynamic Object Creation

Posted 11 January 2013 - 12:35 AM

Normally I would create an object using operator=, as such:
docbook::db5::CsimplesectType pf_ss = pf.simplesect.append();


However, I have the need to create multiple instances of the object. e.g:
static std::vector<docbook::db5::CsimplesectType> object_vector(5);
            
for (unsigned int i = 0; i < object_vector.size() - 1; i++) {
    docbook::db5::CsimplesectType pf_ss[i] = pf.simplesect.append();
}


So that later I can populate the objects:
pf_ss1 = "whatever string"

OR
object_vector[1] = "whatever string"


Obviously, this doesn't work. I would prefer to be able to utilize a string name, as normal, to populate the object. How do I proceed?

Here is a snippet of the relevant header:
namespace docbook
{

namespace db5
{	

class CsimplesectType : public TypeBase
{
public:
	DOCBOOK_EXPORT CsimplesectType(xercesc::DOMNode* const& init);
	DOCBOOK_EXPORT CsimplesectType(CsimplesectType const& init);
	void operator=(CsimplesectType const& other) { m_node = other.m_node; }
	static conforme::meta::ComplexType StaticInfo() { return conforme::meta::ComplexType(types + _conforme_ti_db5_conforme_CsimplesectType); }

	MemberAttribute<string_type,_conforme_mi_db5_conforme_CsimplesectType_conforme_role, 0, 0> role;	// role CanySimpleType

	MemberAttribute<string_type,_conforme_mi_db5_conforme_CsimplesectType_conforme_id, 0, 0> id;	// id CID

	MemberAttribute<string_type,_conforme_mi_db5_conforme_CsimplesectType_conforme_version, 0, 0> version;	// version CanySimpleType
	MemberAttribute<string_type,_conforme_mi_db5_conforme_CsimplesectType_conforme_lang, 0, 1> lang;	// lang ClangType

	MemberAttribute<string_type,_conforme_mi_db5_conforme_CsimplesectType_conforme_base, 0, 0> base;	// base CanyURI
...



Is This A Good Question/Topic? 0
  • +

Replies To: Dynamic Object Creation

#2 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,472
  • Joined: 20-March 10

Re: Dynamic Object Creation

Posted 11 January 2013 - 03:10 AM

Hi,

if the vectors base type is a string

you can just use append like this

        vector<string> object(5);

	object[1].append("whatever");

	cout << object[1].c_str();



Snoopy.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1