pointer to a class member
Hi
I have a class and I declared a pointer to hostent structure in the class. The value of pointer is assigned in the constructor (upon returing from a function). The problem is that all the instances of my class use the same memory address for this structure. I examined the case with gdb and saw that all hostent* point the same memory location. That's why all values of hostent hold for one instance of class are overwritten by another instance. How can I fix this?
Code:
class MyClass
{
public:
....
private:
hostent *h;
};
MyClass::MyClass()
{
...
h= gethostbyname();
...
}
int main()
{
MyClass obj1("aaa");
MyClass obj2("bbb");
// the *h of obj1 and *h of obj2 point the
// same memory location at this point!
retrurn 0;
}