Reflex object instantiation

Hi,

I’m a newbie in Reflex libraries. I want to set a string from an Reflex::Object. But probably i’m doing something wrong.

I want to create an object of the following class:

class TestClass{
public:
TestClass(){};
std::string s;
int i;
};

Type t= Type::ByName(“TestClass”);
o = t.Construct();

o.Set(“i”,23);
o.Set(“s”,“This is a string”);

TestClass res=Object_Cast(o);

I get the object from the object_cast<> and I get that the integer properly( i=23), but the string is empty (""), any ideas why???

Thanks

up!!. Any suggestion?

I have the same problem with other non basic types as vectors. It might be that I’m forgetting something? Should I make a function in my class to get the values (of strings and vectors) by Object.invoke()?

Thank you

Hi,

For non-POD member types, Set() expects the address of the value of the data member, which must be of the same type as the data member. I.e. you need to pass the address of an std::string. Does that help?

Cheers, Axel.

[quote=“Axel”]Hi,

For non-POD member types, Set() expects the address of the value of the data member, which must be of the same type as the data member. I.e. you need to pass the address of an std::string. Does that help?

Cheers, Axel.[/quote]

Thanks, Axel. I’m trying to do it but I get the same result. I cant’ set the value of the string. Do you mean to do this??

Member strMember=t.MemberByName(“s”);
strMember.Set(o,(void*)&(“this is a string”));

Its necessary to load some additional libraries to work with non-POD member types??? (In this case something like string.dll or similar???)

Hi,

no, as I said: you need to pass the address of an std::string, not a string literal.

std::string val("This is a string");
o.Set("s",&val);

Cheers, Axel.