1

the question of InterfaceDescription

asked 2015-07-27 19:11:39 -0700

tianya gravatar image

QStatus InterfaceDescription::AddMember(AllJoynMessageType type, const char* name, const char* inSig, const char* outSig, const char* argNames, uint8_t annotation, const char* accessPerms) {

if (isActivated) {
    return ER_BUS_INTERFACE_ACTIVATED;
}

StringMapKey key = qcc::String(name);
Member member(this, type, name, inSig, outSig, argNames, annotation, accessPerms);
pair<StringMapKey, Member> item(key, member);
pair<Definitions::MemberMap::iterator, bool> ret = defs->members.insert(item);
return ret.second ? ER_OK : ER_BUS_MEMBER_ALREADY_EXISTS;

}

the "member" is allocated on stack, why? when the method return ,the "member" is released,so i can not get the "member"

edit retag flag offensive close merge delete

Comments

1

I might not understood your question fully, but the intention of AddMember is add a member to the InterfaceDescription. If you want to get get the member, you can use GetMember() API.

praveenb ( 2015-07-29 02:10:10 -0700 )edit

"member" is allocated on stack, when addMember() return, the "member" is released. so i can not get the member when i use getMember() .

tianya ( 2015-07-29 07:01:17 -0700 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-09-02 09:26:53 -0700

stevek gravatar image

updated 2015-09-02 09:31:50 -0700

This code is C++, member is being copied; twice actually. It's a bit inefficient, but member is not disappearing.

Member member(this, type, name, inSig, outSig, argNames, annotation, accessPerms);

This instantiates member.

pair<StringMapKey, Member> item(key, member);

This constructs item with a copy of member.

pair<Definitions::MemberMap::iterator, bool> ret = defs->members.insert(item);

This inserts (read as copies) item that contains a copy of member into defs->members. defs-members persists beyond the return of the function.

edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2015-07-27 19:11:39 -0700

Seen: 38 times

Last updated: Sep 02 '15