Hi,
I have following issue, I have pointer object as member variable and I want to return just an object from one function. do I need to rewrite the function or anything else?
//role.h
class Role{
int count;
Manage man; // another class's object
};
//analyze.h
Role *role;
public:
Role getRole() const;
//analyze.cpp
..
..
role = new Role("agent");
..
..
Role Analyze::getRole() const{
if(role)
return ######; ////// I want to return the role object but how to do that as declaration need object but I have *object?
else
return Firm();
}
Yes Firm() actually returns object.
I tried using this but no luck...
Fun2code, I think I have some other issue :)
thanks for your help... I was doubting on my dereferencing concept.
If you return an actual object, then you are creating a copy of the object that's being returned. Depending on how your compiler optimises the executable code it creates, there might well be temporary intermediate copies of the object being created too.
I suspect the reason for the crash is something to do with what happens when you create copies of your Role object, or the Man object it contains.
The obvious question is: why do want to return a copy of the object, rather than a pointer to it? What do you want to achieve that you can't achieve using a pointer?