Why void * return class address instead of actual value address

////////////// Set.h //////////
class Set {
public:
void *set_elements;
int area;
Set(int);
};
////////////// Set.cpp //////////
Set::Set(int object) {
area = object;
set_elements = &object;
}
////////////// Area.h //////////
class Area {
private:
Set *set;

public:
Area();
bool add(Set set);
}
////////////// Area.c //////////
Area::Area(){
set = (Set *)malloc(10);

}

Area::add(Set obj){

set->set_elements = obj.set_elements;
set->area = obj.area;
}

////////////// main.c //////////

int main(){
Area area;
area.add(Set(5));
}

call Area construct is fine, Set(5) work fine but when call add function Set class void * variable change actual value to Set object address value what is reason.
e.g
Set(5) address = 0x0022fe34

Area::add(Set obj){

}

when calling add func. value of set_elements change from &int to &Set by default
what is it problem
please, reedit your post using the code format
A problem is that in the Set constructor you assign set_elements an address of a temporary value. It could point to anything afterwards.
I don't really get what you're trying to do, so can't suggest anything.
Do put it all in [code] tags.
Topic archived. No new replies allowed.